#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<<idx<<' '<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1672 KB |
Output is correct |
2 |
Correct |
0 ms |
1672 KB |
Output is correct |
3 |
Correct |
0 ms |
1672 KB |
Output is correct |
4 |
Correct |
8 ms |
1672 KB |
Output is correct |
5 |
Correct |
0 ms |
1672 KB |
Output is correct |
6 |
Correct |
8 ms |
1672 KB |
Output is correct |
7 |
Correct |
20 ms |
1844 KB |
Output is correct |
8 |
Correct |
20 ms |
1864 KB |
Output is correct |
9 |
Correct |
68 ms |
2060 KB |
Output is correct |
10 |
Correct |
56 ms |
2040 KB |
Output is correct |
11 |
Correct |
32 ms |
2060 KB |
Output is correct |
12 |
Correct |
24 ms |
2040 KB |
Output is correct |
13 |
Correct |
0 ms |
1672 KB |
Output is correct |
14 |
Correct |
4 ms |
1672 KB |
Output is correct |
15 |
Correct |
24 ms |
2052 KB |
Output is correct |