#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int n,p;
cin>>p>>n;
vector<int> vll(n,0);
for(int i=0;i<n;++i) cin>>vll[i];
sort(vll.begin(), vll.end());
int leftTime = p-1;
long long ans = 0, idx = 0;
while( leftTime >= 0 ){
if(idx < vll.size() && vll[idx] <= leftTime){
ans += leftTime;
leftTime -= vll[idx];
idx++;
}
else break;
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |