bài 95 program bt; var a: array[1..100,1..100] of longint; - TopicsExpress



          

bài 95 program bt; var a: array[1..100,1..100] of longint; b: array[1..100] of longint; n,m,i,j,t,t1: longint; kt: boolean; f: text; begin assign(f,input.txt); reset(f); read(f,m,n); for i:= 1 to n do begin read(f,a[i,1],a[i,2]); a[i,3]:= i; end; for i:= 1 to n-1 do for j:= i+1 to n do if a[i,2] > a[j,2] then begin t:= a[i,1]; a[i,1]:= a[j,1]; a[j,1]:= t; t:= a[i,2]; a[i,2]:= a[j,2]; a[j,2]:= t; t:= a[i,3]; a[i,3]:= a[j,3]; a[j,3]:= t; end; t:= 0; for i:= 1 to n do begin t1:= 0; for j:= 1 to a[i,1] do begin if m = 0 then break; m:= m - 1; t:= t + a[i,2]; t1:= t1 + 1; end; b[a[i,3]]:= t1; end; assign(f,output.txt); rewrite(f); writeln(f,t); for i:= 1 to n do writeln(f,b[i]); close(f); end.
Posted on: Sat, 03 Jan 2015 13:39:29 +0000

Trending Topics



Recently Viewed Topics




© 2015