比赛 聪明的工作员 评测结果 WWWWWTTTWTTTTTTTTTTT
题目名称 聪明的质监员 最终得分 0
用户昵称 Regnig Etalsnart 运行时间 14.007 s
代码语言 C++ 内存使用 3.36 MiB
提交时间 2017-03-21 20:44:52
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=200005;
int n,m,s,l[maxn],r[maxn],minl=maxn,maxr=0,mid,w[maxn],v[maxn],sum_n,sum_v,minn=0x7f,s_ans,i,j;
void input()
{
	scanf("%d%d%d",&n,&m,&s);
	for(i=1;i<=2*n;i++)
	{
		if(i%2==1)scanf("%d",&w[i/2+1]);
		if(i%2==0)scanf("%d",&v[i/2]);
	}
	for(i=1;i<=m;i++)
	{
		scanf("%d%d",&l[i],&r[i]);
		if(minl>l[i])minl=l[i];
		if(maxr<r[i])maxr=r[i];
	}
}
int play(int minl,int maxr)
{
	if(minl==maxr)return minn;
	s_ans=0;
	mid=(minl+maxr)/2;
	for(i=1;i<=m;i++)
	{
		for(j=l[i];j<=r[i];j++)
		{			
			if(w[j]>=mid)
			{				
				sum_n++;
				sum_v+=v[j];
			}		
		}
		s_ans+=sum_n*sum_v;
	}
	if(minn>abs(s-s_ans))
	  minn=abs(s-s_ans);
	if(s_ans>s)return play(minl,mid);
	if(s_ans<s)return play(mid,maxr);
	if(s_ans==s)return minn;
}
int main()
{
	freopen("qc.in","r",stdin);freopen("qc.out","w",stdout);
	input();
	printf("%d",play(minl,maxr));
}