|
沙发
楼主 |
发表于 2018-10-6 18:02:35
|
只看该作者
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- #define FOR(i,a,b) for(register int i=a;i<=b;i++)
- #define ROF(i,a,b) for(register int i=a;i>=b;i--)
- using namespace std;
- const int N=200005;
- long long int n,m,S,sum[N],sumn[N],w[N],v[N],ans=0x7fffffffff,minw=0x7fffffff,maxw=-1,an,k,l[N],r[N];
- inline long long int abs(long long int x,long long int y){if(x>y)return x-y;else return y-x;}
- bool check(int x)
- {
- k=0;an=0;
- memset(sum,0,sizeof(sum));
- memset(sumn,0,sizeof(sumn));
- FOR(i,1,n)
- {
- sum[i]=sum[i-1];sumn[i]=sumn[i-1];
- if(w[i]>=x){sum[i]+=v[i];sumn[i]+=1;}
- }
- FOR(i,1,m)k+=(sum[r[i]]-sum[l[i]-1])*(sumn[r[i]]-sumn[l[i]-1]);
- an=abs(S,k);
- if(S>k)return true;
- else return false;
- }
- int main()
- {
- cin>>n>>m>>S;
- FOR(i,1,n){cin>>w[i]>>v[i];minw=min(minw,w[i]);maxw=max(maxw,w[i]);}
- FOR(i,1,m)cin>>l[i]>>r[i];
- long long int L=minw-1,R=maxw+2,mid;
- while(L<=R)
- {
- mid=L+((R-L)>>1);
- if(check(mid))R=mid-1;
- else L=mid+1;
- if(an<ans)ans=an;
- }
- cout<<ans<<endl;
- return 0;
- }
复制代码 |
|