记录编号 78335 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [NOIP 2011]聪明的质监员 最终得分 100
用户昵称 Gravatar正确率超低的渣渣 是否通过 通过
代码语言 Pascal 运行时间 0.712 s
提交时间 2013-11-03 19:58:30 内存使用 4.74 MiB
显示代码纯文本
program qc (input,output);
var
i,j,n,m,wait,min,half,max:longint;
w,v,l,r,sum,gs:array[0..200001]of longint;
y,s,o1,o2,ans:int64;
begin
assign(input,'qc.in');
reset(input);
assign(output,'qc.out');
rewrite(output);


   readln(n,m,s);
   wait:=0;
   for i:=1 to n do
   begin
   readln(w[i],v[i]);
   if w[i]>wait then  wait:=w[i];
   end;

   for i:=1 to m do
   readln(l[i],r[i]);

   min:=0;
   max:=wait+1;
   ans:=231542134135465422;
repeat
   half:=(max+min)div 2;
   for i:=1 to n do
   if w[i]>=half then begin
                      gs[i]:=gs[i-1]+1;
                      sum[i]:=sum[i-1]+v[i];
                      end
                 else begin
                      gs[i]:=gs[i-1];
                      sum[i]:=sum[i-1];
                      end;
   y:=0;
   for i:=1 to m do
   begin
   o1:=gs[r[i]]-gs[l[i]-1];
   o2:=sum[r[i]]-sum[l[i]-1];
   y:=y+  o1*o2;
   end;


   if y>s then min:=half
          else max:=half;
   if abs(y-s)<ans then ans:=abs(y-s);
until max-min=1 ;
writeln(ans);

close(input);
close(output);
end.