比赛 |
20101117 |
评测结果 |
AWWWWWWWWA |
题目名称 |
物品 |
最终得分 |
20 |
用户昵称 |
donny |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-17 10:01:34 |
显示代码纯文本
program magica;
var
n,p,q,o:longint;
r,s,t:longint;
i,j,k,l:longint;
a:array[1..1000,1..3]of longint;
money:longint;
procedure sort(const x,y:longint);
var
i,j,k,l:longint;
begin
i:=x;
j:=y;
k:=a[(x+y)div 2,3];
repeat
while a[i,3]<k do inc(i);
while a[j,3]>k do dec(j);
if i<=j then
begin
l:=a[i,1];
a[i,1]:=a[j,1];
a[j,1]:=l;
l:=a[i,2];
a[i,2]:=a[j,2];
a[j,2]:=l;
l:=a[i,3];
a[i,3]:=a[j,3];
a[j,3]:=l;
inc(i);
dec(j);
end;
until i>j;
if x<j then sort(x,j);
if i<y then sort(i,y);
end;
begin
assign(input,'magica.in');
reset(input);
assign(output,'magica.out');
rewrite(output);
money:=0;
readln(n,p);
r:=0;
for i:=1 to n do
begin
read(j);
if not eoln then
begin
readln(k);
if (k-j>p) then
begin
inc(r);
a[r,1]:=j;
a[r,2]:=k;
a[r,3]:=k-j;
end
else
money:=money+j;
end
else
begin
money:=money+j;
readln;
end;
end;
i:=1;
if money<p then
begin
sort(1,r);
while money <p do
begin
money:=money+a[i,1];
inc(i);
end;
end;
for j:=i to r do
begin
money:=money+a[j,2]-p;
end;
writeln(money);
close(input);
close(output);
end.