Pagini recente » Cod sursa (job #630180) | Cod sursa (job #2793863) | Cod sursa (job #1996876) | Cod sursa (job #1822344) | Cod sursa (job #125024)
Cod sursa(job #125024)
type gardieni=record
a,b,c:longint;
end;
var p:array[1..50005]of gardieni;
n,t,i,k,s,h:longint;
ok:boolean;
aux:gardieni;
f,g:text;
begin
assign(f,'gardieni.in');
reset(f);
read(f,n);
readln(f,t);
for i:=1 to n do
with p[i] do begin
read(f,a);
read(f,b);
readln(f,c);
end;
close(f);
repeat
ok:=true;
for i:=1 to n-1 do
if p[i].c>p[i+1].c then begin
aux:=p[i];
p[i]:=p[i+1];
p[i+1]:=aux;
ok:=false;
end;
until ok=true;
i:=0;
s:=0;
repeat
inc(i);
k:=abs(p[i].b-p[i].a)+1;
if k>t then begin
h:=t;
t:=t-k;
end
else t:=t-k;
if t>=0 then s:=s+(p[i].c*k)
else if t<0 then s:=s+(p[i].c*(h));
until t<=0;
assign(g,'gardieni.out');
rewrite(g);
writeln(g,s);
close(g);
end.