#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <utility>
#include <bitset>
#include <iostream>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
int n, a[100005], p;
int main(){
scanf("%d %d",&p,&n);
for(int i=0; i<n; i++){
scanf("%d",&a[i]);
}
sort(a, a+n);
int q = 0, s = n;
for(int i=0; i<n; i++){
q += a[i];
if(q >= p){
s = i;
break;
}
}
lint ret = 0, sum = 0;
for(int i=0; i<s; i++){
ret += p - 1 - sum;
sum += a[i];
}
printf("%d %lld\n",s,ret);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2112 KB |
Output is correct |
2 |
Correct |
0 ms |
2112 KB |
Output is correct |
3 |
Correct |
0 ms |
2112 KB |
Output is correct |
4 |
Correct |
0 ms |
2112 KB |
Output is correct |
5 |
Correct |
0 ms |
2112 KB |
Output is correct |
6 |
Correct |
4 ms |
2112 KB |
Output is correct |
7 |
Correct |
12 ms |
2112 KB |
Output is correct |
8 |
Correct |
11 ms |
2112 KB |
Output is correct |
9 |
Correct |
16 ms |
2112 KB |
Output is correct |
10 |
Correct |
29 ms |
2112 KB |
Output is correct |
11 |
Correct |
14 ms |
2112 KB |
Output is correct |
12 |
Correct |
14 ms |
2112 KB |
Output is correct |
13 |
Correct |
0 ms |
2112 KB |
Output is correct |
14 |
Correct |
0 ms |
2112 KB |
Output is correct |
15 |
Correct |
8 ms |
2112 KB |
Output is correct |