#include <stdio.h>
#include <algorithm>
using namespace std;
int x[100000];
int main(void)
{
int P, N, i, t;
long long S = 0;
scanf("%d %d", &P, &N);
for(i = 0; i < N; i++)
scanf("%d", x + i);
sort(x, x + N);
t = P - 1;
for(i = 0; i < N && t >= 0; i++)
{
if(t - x[i] >= 0)
S += t;
else
break;
t -= x[i];
}
printf("%d %lld\n", i, S);
return 0;
}
# |
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 |
4 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 |
12 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 |
8 ms |
1476 KB |
Output is correct |