比赛 平凡的题目 评测结果 AWWWWTTTTA
题目名称 平凡的题面 最终得分 20
用户昵称 Ten.X 运行时间 4.010 s
代码语言 Pascal 内存使用 1.88 MiB
提交时间 2015-11-03 10:38:24
显示代码纯文本
var v,vv:array[1..100005]of boolean;
	a,a_l,a_r,w:array[1..100005]of longint;
	n,m,i,j,tot:longint;
	procedure qsort1(s,t:longint);
    var i,j,mid,temp:longint;
      begin
        i:=s;j:=t;mid:=w[(s+t) div 2];
        while i<=j do
        begin
          while w[i]<mid do inc(i);
          while w[j]>mid do dec(j);
          if i<=j then
            begin
              temp:=w[i];w[i]:=w[j];w[j]:=temp;
              inc(i);dec(j);
            end;
        end;
        if i<t then qsort1(i,t);
        if j>s then qsort1(s,j);
      end;
	  procedure qsort2(s,t:longint);
    var i,j,mid,temp:longint;
      begin
        i:=s;j:=t;mid:=a[(s+t) div 2];
        while i<=j do
        begin
          while a[i]<mid do inc(i);
          while a[j]>mid do dec(j);
          if i<=j then
            begin
			  temp:=a[i];a[i]:=a[j];a[j]:=temp;
              temp:=a_l[i];a_l[i]:=a_l[j];a_l[j]:=temp;
			  temp:=a_r[i];a_r[i]:=a_r[j];a_r[j]:=temp;
              inc(i);dec(j);
            end;
        end;
        if i<t then qsort2(i,t);
        if j>s then qsort2(s,j);
      end;
function judge(x,y:longint):boolean;
begin
if (w[x]>=a_l[y]) and(w[x]<=a_r[y]) then exit(true) else exit(false);
end;
begin
assign(input,'bg.in');
assign(output,'bg.out');
reset(input);
rewrite(output);
tot:=0;
fillchar(v,sizeof(v),false);
fillchar(vv,sizeof(vv),false);
read(n,m);
for i:=1 to n do read(w[i]);
for i:=1 to m do begin read(a_l[i],a_r[i]);a[i]:=a_l[i]+a_r[i];end;
qsort1(1,n);
qsort2(1,m);
 for i:=1 to n do
  for j:=1 to m do
  if (not vv[i])and(not v[j])and(judge(i,j)) then
  begin inc(tot);v[j]:=true;vv[i]:=true;end;
 write(tot);
 close(input);
 close(output);
end.