#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,d,anw,sum,id;
vector<ll> x;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cin>>m>>d>>n;
for(int i=0;i<n;i++)
{
ll a;cin>>a;
x.emplace_back(a);
}
sort(x.begin(),x.end());
ll i=n-1;
while(sum<m&&i>=0)
{
sum+=x[i]-max((ll)0,abs(d-sum)),anw++;
i--;
}
if(sum>=m)
{
cout<<anw;
return 0;
}
id=lower_bound(x.begin(),x.end(),m-d)-x.begin();
if(id==n)
{
cout<<0;
return 0;
}
i=n-1,sum=0,anw=1;
while(sum<d&&i>=0)
{
if(i==id)
{
i--;
continue;
}
sum+=x[i]-max((ll)0,abs(d-sum)),anw++;
i--;
}
if(sum<d)
cout<<0;
else
cout<<anw;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
512 KB |
Output is correct |
2 |
Incorrect |
3 ms |
500 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1280 KB |
Output is correct |
2 |
Correct |
7 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
1788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
1916 KB |
Output is correct |
2 |
Incorrect |
61 ms |
3188 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
5368 KB |
Output is correct |
2 |
Incorrect |
110 ms |
6504 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
147 ms |
5280 KB |
Output is correct |
2 |
Incorrect |
124 ms |
5096 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
124 ms |
5224 KB |
Output is correct |
2 |
Incorrect |
138 ms |
5248 KB |
Output isn't correct |