#include<stdio.h>
#include<algorithm>
using std::sort;
int data[100011];
int main(void)
{
int a, i, sum, n, t = 0, result, r = 0;
scanf("%d %d",&a,&n);
for(i = 0; i < n; i++)
scanf("%d",&data[i]);
sort( data, data+n );
sum = 0;
for(i = 0; i < n; i++)
{
r = sum;
sum += data[i];
if( sum >= a ) break;
}
r = a-r-1;
result = i;
t = 0;
sum = r;
for(i = result-1; i >= 0; i--)
{
sum += data[i];
t += sum;
}
printf("%d %d",result,t);
}
# |
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 |
Incorrect |
24 ms |
1476 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |