#include <stdio.h>
#include <algorithm>
using namespace std;
int a[100010],t;
long long s;
int main(){
int i,p,n;
scanf("%d%d",&p,&n);
for(i=1;i<=n;++i)scanf("%d",a+i);
sort(a+1,a+n+1);
--p;
for(i=1;i<=n;++i){
if(p<a[i])break;
s+=p;
p-=a[i];
}
printf("%d %lld",--i,s);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1472 KB |
Output is correct |
2 |
Correct |
0 ms |
1472 KB |
Output is correct |
3 |
Correct |
0 ms |
1472 KB |
Output is correct |
4 |
Correct |
4 ms |
1472 KB |
Output is correct |
5 |
Correct |
0 ms |
1472 KB |
Output is correct |
6 |
Correct |
4 ms |
1472 KB |
Output is correct |
7 |
Correct |
11 ms |
1472 KB |
Output is correct |
8 |
Correct |
8 ms |
1472 KB |
Output is correct |
9 |
Correct |
31 ms |
1472 KB |
Output is correct |
10 |
Correct |
21 ms |
1472 KB |
Output is correct |
11 |
Correct |
11 ms |
1472 KB |
Output is correct |
12 |
Correct |
10 ms |
1472 KB |
Output is correct |
13 |
Correct |
0 ms |
1472 KB |
Output is correct |
14 |
Correct |
0 ms |
1472 KB |
Output is correct |
15 |
Correct |
14 ms |
1472 KB |
Output is correct |