比赛 |
20120709 |
评测结果 |
EEEEEEEEEE |
题目名称 |
数列 |
最终得分 |
0 |
用户昵称 |
张弛 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.41 MiB |
提交时间 |
2012-07-09 10:23:17 |
显示代码纯文本
program kkxx;
var
a,time,name1,name2:array[1..10000] of longint;
f:array[1..100000] of boolean;
i,j,n,p,r,t,max,min,t1,c:longint;
procedure sort(l,r:longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=time[(l+r) div 2];
repeat
while time[i]<x do
inc(i);
while x<time[j] do
dec(j);
if not(i>j) then
begin
y:=time[i];
time[i]:=time[j];
time[j]:=y;
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
begin
assign(input,'salenet.in');reset(input);
assign(output,'salenet.out');rewrite(output);
readln(n,p);
for i:=1 to p do
readln(a[i],time[i]);
fillchar(f,sizeof(f),false);
readln(r);
for i:=1 to r do
readln(name1[i],name2[i]);
sort(1,p);
t:=0;
while t<p do
begin
inc(t);
if not f[a[t]] then begin f[a[t]]:=true; max:=max+time[t]; end;
for i:=1 to r do
if name1[i]=a[t] then f[name2[i]]:=true;
end;
for i:=1 to n do
if f[i] then inc(min)
else begin inc(t1); c:=i; break; end;
if t1=0 then begin writeln('YES'); writeln(max); end
else begin writeln('NO'); writeln(c); end;
if min=n then
else
close(input);close(output);
end.