记录编号 74011 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [NOIP 2011]聪明的质监员 最终得分 100
用户昵称 Gravatargungnir 是否通过 通过
代码语言 Pascal 运行时间 1.193 s
提交时间 2013-10-23 18:58:51 内存使用 48.32 MiB
显示代码纯文本
var
w,v,g:array[0..2000005]of longint;
p,q:array[0..2000005]of longint;
s:array[0..2000005]of int64;
ss,ans,min:int64;
m,n,i,j:longint;
l,r,fk:longint;


begin
assign(input,'qc.in');reset(input);
assign(output,'qc.out');rewrite(output);
readln(n,m,ss);
for i:=1 to n do readln(w[i],v[i]);
for i:=1 to m do readln(p[i],q[i]);
l:=0; r:=1000000000;
min:=-1;

  while l<r do
  begin
  fk:=(l+r)div 2;
  g[0]:=0;
  s[0]:=0;
  ans:=0;
  for j:=1 to n do
  if w[j]>=fk then begin g[j]:=g[j-1]+1; s[j]:=s[j-1]+v[j]; end
              else begin g[j]:=g[j-1]; s[j]:=s[j-1]; end;
  for j:=1 to m do ans:=ans+(g[q[j]]-g[p[j]-1])*(s[q[j]]-s[p[j]-1]);
  if(min=-1)or(abs(ans-ss)<min) then min:=abs(ans-ss);
  if ans>ss then l:=fk+1 else r:=fk;
  end;
writeln(min);
close(input);close(output);
end.