#include <cstdio>
#include <algorithm>
using namespace std;
int Problem[100000];
int main() {
int P, N;
scanf("%d %d",&P,&N);
for(int i=0;i<N;i++)
scanf("%d",Problem+i);
sort(Problem,Problem+N);
int sum = 0, idx = 0;
for(int i=0;i<N;i++) {
sum += Problem[i];
if(sum >= P)
break;
idx = i;
}
printf("%d ",idx+1); // Maximum solving problems
for(int i=idx-1;i>=0;i--)
Problem[i] += Problem[i+1];
long long panelty = 0;
for(int i=idx;i>=0;i--)
panelty += Problem[i] + P-Problem[0]-1;
printf("%lld",panelty);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1476 KB |
Output is correct |
2 |
Correct |
0 ms |
1476 KB |
Output is correct |
3 |
Correct |
0 ms |
1476 KB |
Output is correct |
4 |
Correct |
0 ms |
1476 KB |
Output is correct |
5 |
Correct |
0 ms |
1476 KB |
Output is correct |
6 |
Correct |
4 ms |
1476 KB |
Output is correct |
7 |
Correct |
8 ms |
1476 KB |
Output is correct |
8 |
Correct |
8 ms |
1476 KB |
Output is correct |
9 |
Correct |
24 ms |
1476 KB |
Output is correct |
10 |
Correct |
20 ms |
1476 KB |
Output is correct |
11 |
Correct |
16 ms |
1476 KB |
Output is correct |
12 |
Correct |
12 ms |
1476 KB |
Output is correct |
13 |
Correct |
0 ms |
1476 KB |
Output is correct |
14 |
Correct |
0 ms |
1476 KB |
Output is correct |
15 |
Correct |
12 ms |
1476 KB |
Output is correct |