#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
int n,su[100001];
int main(){
int n,m,i;
scanf("%d %d",&m,&n);
for(i=0;i<n;i++)
scanf("%d",&su[i]);
std::sort(su,su+n);
int sum=0,s;
long long print=0,now;
for(i=0;i<n;i++){
if(sum+su[i]>=m) break;
sum+=su[i];
}
s=i;
i--;
now=m-sum-1;
for(;i>=0;i--){
print+=now+su[i];
now+=su[i];
}
printf("%d %lld\n",s,print);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
24 ms |
1476 KB |
Output is correct |
11 |
Correct |
12 ms |
1476 KB |
Output is correct |
12 |
Correct |
8 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 |