Pagini recente » Cod sursa (job #1948439) | Cod sursa (job #830418) | Cod sursa (job #254818) | Rating UAIC 3Licee (UAIC_Bejan_Gotca_Lungu) | Cod sursa (job #28740)
Cod sursa(job #28740)
var e,c:array[1..1001]of integer;
n,p,i,t,l,k:integer;
r:array[1..1001]of real;
max:real;
f,g:text;
begin
assign(f,'energii.in');
reset(f);
assign(g,'energii.out');
rewrite(g);
readln(f,n);
readln(f,t);
for i:=1 to n do begin
readln(f,e[i],c[i]);
if c[i]=0 then r[i]:=1000*1000
else r[i]:=e[i]/c[i];
end;
l:=0;
while l=0 do begin
max:=-1;
for i:=1 to n do
if r[i]>max then begin
max:=r[i];
p:=i;
end;
if max=-1 then l:=2;
if t>e[p] then begin
t:=t-e[p];
k:=k+c[p];
e[p]:=-2;
c[p]:=-2;
r[p]:=-2;
end
else if t=e[p] then begin
l:=1;
k:=k+c[p];
end
else l:=2;
end;
if l=2 then begin
p:=9999;
for i:=1 to n do if (t<e[i]+1)and(c[i]<p) then p:=c[i];
k:=k+p;
end;
if p=9999 then write(g,'-1')
else write(g,k);
close(g);
end.