const fi='candy1051.inp';fo='candy1051.out'; var a,b:array[0..round(1e6)]of int64; n,m,res:longint; procedure nhap; var i:longint; begin readln(n,m); for i:=1 to n do read(A[i]); end; function check(x:longint):boolean; var i:longint; res:int64; begin res:=0; for i:=1 to n do if a[i]<x then res:=res+x-a[i]; if res<=m then exit(true) else exit(false); end; function bs(l,r:int64):int64; var mid,res:int64; begin res:=-1; while l<=r do begin mid:=(l+r) div 2; if check(mid)=true then begin l:=mid+1; res:=mid; end else r:=mid-1; end; exit(res); end; procedure xuli; var i,j:longint;k:int64; begin for i:=1 to n do b[i]:=a[i]; //qs(1,n); k:=bs(0,trunc(1e9)*2); for i:=1 to n do if a[i]<k then begin m:=m-(k-a[i]); a[i]:=k; end; for i:=1 to n do begin if m>0 then if a[i]=k then begin a[i]:=k+1; dec(m); end; end; { end; for i:=n downto 1 do if b[i]<res then begin m:=m-(res-1-b[i]); b[i]:=res-1; end; for i:=1 to n do if m>0 then if b[i]<res then begin b[i]:=res; dec(m); end;} for i:=1 to n do write(a[i],' '); end; begin assign(input,fi);reset(input); assign(output,fo);rewrite(output); nhap; xuli; end.
* Chuyên dạy lập trình ONLINE cho học sinh THCS, THPT *.
Mọi giao lưu, trao đổi, xin liên hệ: Lê Quang Vinh - zalo: 037.803.8755.
Page: Lớp học Code Sky
Group FB1: Ôn thi HSG9 - THTB - TS10 chuyên tin
Group FB2: Học Scratch - Ôn thi Tin học trẻ bảng A
Thứ Ba, 3 tháng 5, 2022
CANDY1051 PAS
Đăng ký:
Đăng Nhận xét (Atom)
Không có nhận xét nào:
Đăng nhận xét
Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.