记录编号 314042 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [NOIP 2011]聪明的质监员 最终得分 100
用户昵称 Gravatar哒哒哒哒哒! 是否通过 通过
代码语言 C++ 运行时间 0.488 s
提交时间 2016-10-02 16:30:44 内存使用 43.76 MiB
显示代码纯文本
#include<cstdio>
#include<vector>
#include<algorithm>
#define Cu fclose(stdin);fclose(stdout);return 0;
#define Begin freopen("qc.in","r",stdin);freopen("qc.out","w",stdout);chul();Cu;
using namespace std;
typedef unsigned long long ll;
const ll maxn=200010*5;
struct op{
	ll w,v;
}re[maxn];
ll s,t,x1,x2;
struct po{
	ll s,t;
}a[maxn];
ll sum[maxn],tot[maxn];
ll n,m,k;
ll min(ll x,ll y){
	if(x>y)return y;
	return x;
}
ll getmigh(ll x,ll y){
	if(x>y)return x-y;
	return y-x;
}
ll check(ll wi){
	ll ret=0;
	for(int i=1;i<=n;i++){
		if(re[i].w>=wi){
			sum[i]=sum[i-1]+1;
			tot[i]=tot[i-1]+re[i].v;
		}
		else sum[i]=sum[i-1],tot[i]=tot[i-1];
	}
	for(int i=1;i<=m;i++){
		ret+=((sum[a[i].t]-sum[a[i].s-1])*(tot[a[i].t]-tot[a[i].s-1]));
	}
	return ret;
}
void clean(ll wt){
	ll si=0,ti=wt,mid,ans;
	while(si<=ti){
		mid=(si+ti)>>1;
		ll y=check(mid);
		ans=min(ans,getmigh(y,k));
		if(y==k) break;
		if(y<k) ti=mid-1;
		else si=mid+1;
	}
	//printf("si=%llu ti=%llu\n",si,ti);
	printf("%llu\n",ans);
}
ll max(ll x,ll y){
	if(x>y)return x;
	return y;
}
void chul(){
	scanf("%llu%llu%llu",&n,&m,&k);
	ll wt=0;
	for(ll i=1;i<=n;i++){
		scanf("%llu%llu",&re[i].w,&re[i].v);
		wt=max(wt,re[i].w);
	}
	for(ll i=1;i<=m;i++)scanf("%llu%llu",&a[i].s,&a[i].t);
	clean(wt);
}	
int main(){
	Begin;
}