type pt=record
cs,gt:longint;
end;
var a:array[0..100000] of pt;
kq:array[0..1000005] of int64;
n,m,tb,s:int64;
procedure nhap;
var i:longint;
begin
readln(n,m);
for i:=1 to n do
begin
read(a[i].gt);
a[i].cs:=i;
s:=s+a[i].gt;
end;
end;
procedure sort(l,r:longint);
var i,j,mid:longint;
t:pt;
begin
i:=l;
j:=r;
mid:=a[l+random(r-l+1)].gt;
repeat
while a[i].gt < mid do inc(i);
while a[j].gt > mid do dec(j);
if i <= j then
begin
t:=a[i];a[i]:=a[j];a[j]:=t;
inc(i); dec(j);
end;
until i>j;
if l < j then
sort(l,j);
if i < r then
sort(i,r);
end;
procedure xuly;
var i:longint;
begin
sort(1,n);
if s < m then
begin
writeln(-1);
exit;
end;
for i:=1 to n do
begin
tb:=m div (n+1-i);
if a[i].gt <= tb then
kq[a[i].cs]:=a[i].gt
else
kq[a[i].cs]:=tb;
m:=m-kq[a[i].cs];
end;
for i:=1 to n do write(kq[i],' ');
end;
begin
assign(input,'SHARE948.inp');reset(input);
assign(output,'SHARE948.out');rewrite(output);
nhap;
xuly;
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
SHARE948 PASCAL
Đă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.