比赛 防止颓废的小练习v0.15 评测结果 WWWAWWAWAWWWWWAWWWWW
题目名称 聪明的质监员 最终得分 20
用户昵称 ConanQZ 运行时间 1.278 s
代码语言 Pascal 内存使用 10.84 MiB
提交时间 2016-10-17 21:19:56
显示代码纯文本
program P1926;
var
lan:array[1..200010]of int64;
lav:array[1..200010]of int64;
n,m,ll,rr,mid,x:int64;
w,v,ww:array[1..200010]of int64;
l,r:array[0..200010]of int64;
ans,k,s:int64;
i:longint;

procedure sort(l,r:longint);
var
i,j,mid:longint;
tmp:int64;
begin
i:=l; j:=r;
mid:=ww[(l+r)>>1];
repeat
while ww[i]<mid do inc(i);
while ww[j]>mid do dec(j);
if i<=j then
  begin
   tmp:=ww[i]; ww[i]:=ww[j]; ww[j]:=tmp;
   inc(i); dec(j);
  end;
until i>j;
if i<r then sort(i,r);
if j>l then sort(l,j);
end;

procedure make_the_arr(mid:longint);
var
i:longint;
begin
fillchar(lan,sizeof(lan),0);
fillchar(lav,sizeof(lav),0);
for i:=1 to n do
   if w[i]>=mid then
     begin
      inc(lan[i]);
      inc(lav[i],v[i]);
     end;
for i:=2 to n do
  begin
   inc(lan[i],lan[i-1]);
   inc(lav[i],lav[i-1]);
  end;
end;

function check(mid:longint):int64;
var
i:longint;
k:int64;
begin
k:=0;
for i:=1 to m do
   inc(k,(lan[r[i]]-lan[l[i]-1])*(lav[r[i]]-lav[l[i]-1]));
exit(k);
end;

begin
assign(input,'qc.in'); reset(input);
assign(output,'qc.out'); rewrite(output);
readln(n,m,s);
for i:=1 to n do
  begin
   readln(w[i],v[i]);
   ww[i]:=w[i];
  end;
for i:=1 to m do readln(l[i],r[i]);
sort(1,n);
k:=1;
for i:=2 to n do
  begin
   if ww[i]<>ww[k] then
     begin
      inc(k);
      ww[k]:=ww[i];
     end;
  end;
ll:=1; rr:=k;
k:=-1;
while ll<rr do
  begin
   mid:=(ll+rr+1)>>1;
   x:=ww[mid];
   make_the_arr(x);
   ans:=check(x);
   if (k=-1)or(abs(s-ans)<=k) then k:=abs(s-ans);
   if ans<=s then rr:=mid-1 else ll:=mid;
  end;
writeln(k);
end.