#include <algorithm>
#include <cstdio>
#include <vector>
typedef long long ll;
using namespace std;
int P, N;
pair<int,ll> solve(const vector<int>& p) {
int cnt = -1, st = 0;
while (st + p[cnt+1] < P) {
st += p[cnt+1];
cnt++;
}
cnt += 1;
int extra = P - st - 1;
int sum = 0;
for (int i = 0; i < cnt; ++i) {
sum += (cnt-i) * p[cnt-i-1];
}
return make_pair(cnt, sum + extra * cnt);
}
int main() {
scanf("%d%d", &P, &N);
vector<int> penalty(N, 0);
for (int i = 0; i < N; ++i)
scanf("%d", &penalty[i]);
sort(penalty.begin(), penalty.end());
pair<int,ll> res = solve(penalty);
printf("%d %lld\n", res.first, res.second);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1236 KB |
Output is correct |
2 |
Correct |
0 ms |
1236 KB |
Output is correct |
3 |
Correct |
0 ms |
1236 KB |
Output is correct |
4 |
Correct |
4 ms |
1236 KB |
Output is correct |
5 |
Correct |
0 ms |
1236 KB |
Output is correct |
6 |
Correct |
4 ms |
1236 KB |
Output is correct |
7 |
Correct |
4 ms |
1408 KB |
Output is correct |
8 |
Correct |
8 ms |
1428 KB |
Output is correct |
9 |
Incorrect |
20 ms |
1624 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |