

Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
Code full
var
a:array[1..1000] of longint;
m,n,i,d,k:longint;
procedure sort(l,r: longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do
inc(i);
while x<a[j] do
dec(j);
if not(i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
begin
readln(n,m);
for i:=1 to n do read(a[i]);
sort(1,n);
k:=1; d:=0;
for i:=n downto 1 do
if k>=m then begin write(d) ; break; end
else
begin
inc(d);
k:=k+a[i]-1;
end;
if k<m then write('-1');
end.
Hãy giúp mọi người biết câu trả lời này thế nào?
Code c++:
#include <bits/stdc++.h>
using namespace std;
//khai bao bla bla ;
long long a[10005];
long long n,m,slongcam,slnoicam=1;
int main()
{
cin>>n>>m;
if (m<=1)
{
cout<<0;
return 0;
}
for (int i=1;i<=n;i++)
cin>>a[i];
sort (a+1,a+n+1,greater<long long>());
for (int i=1;i<n;i++)
{
slnoicam+=a[i]-1;
if (slnoicam>=m)
{
cout<<i;
return 0;
}
}
cout<<-1;
}
Hãy giúp mọi người biết câu trả lời này thế nào?
Bảng tin
878
16288
459
trung bình đàn ông bắt chuyện là để tán
31
142
23
=) vaiz
31
142
23
tke cho tán vs
878
16288
459
ko
878
16288
459
ủa
878
16288
459
đâu r
31
142
23
đây
878
16288
459
:))))