This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |