#include <stdio.h>
#include <algorithm>
using namespace std;
long long num[100000]={0};
int main()
{
long long p,i,j,n;
long long sum=0,res=0,temp;
scanf("%lld %lld",&p,&n);
for(i=0 ; i<n ; i++){
scanf("%lld",&num[i]);
}i=0;
sort(num,num+n);
while(sum + num[i] <= p-1){
sum += num[i++];
}
printf("%d ",i);
temp = p-1-sum;
while(i--){
res += temp + num[i];
temp += num[i];
}
printf("%lld\n",res);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1868 KB |
Output is correct |
2 |
Correct |
0 ms |
1868 KB |
Output is correct |
3 |
Correct |
0 ms |
1868 KB |
Output is correct |
4 |
Correct |
4 ms |
1868 KB |
Output is correct |
5 |
Correct |
0 ms |
1868 KB |
Output is correct |
6 |
Correct |
0 ms |
1868 KB |
Output is correct |
7 |
Correct |
8 ms |
1868 KB |
Output is correct |
8 |
Correct |
8 ms |
1868 KB |
Output is correct |
9 |
Correct |
24 ms |
1868 KB |
Output is correct |
10 |
Correct |
24 ms |
1868 KB |
Output is correct |
11 |
Incorrect |
16 ms |
1868 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |