#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<math.h>
#include<stdlib.h>
using namespace std;
int p[100010],n,k;
int main()
{
scanf("%d%d",&k,&n);
int i;
for(i=0;i<n;i++)scanf("%d",p+i);
sort(p,p+n);
long long s=0;
for(i=0;i<n;i++){
if(s>=k)break;
s+=p[i];
if(s>=k)break;
}
printf("%d ",i);
long long ans=0,t=0;
for(int j=0;j<i;j++){
ans+=(k-1-t);
t+=p[j];
}
printf("%lld",ans);
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 |
4 ms |
1476 KB |
Output is correct |
9 |
Correct |
16 ms |
1476 KB |
Output is correct |
10 |
Correct |
24 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 |