#pragma warning(disable:4996)
#include <algorithm>
#include <functional>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
long long P;
int n;
vector<int> a;
int main() {
cin >> P >> n;
a.resize(n);
for(int i=0; i<n; ++i) cin >> a[i];
sort(a.begin(), a.end(), greater<int>());
long long sum = 0;
long long ws = 0;
int problems = 0;
long long ans = 0;
int ansp = 0;
for(int i = n - 1; i >= 0; -- i) {
sum += a[i];
long long start_time = P-1-sum;
if(start_time < 0) continue;
problems ++;
long long penalty = problems * sum - ws + problems * start_time;
if(ans < penalty) {
ans = penalty;
ansp = problems;
}
ws += sum;
}
cout << ansp << ' ' << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1672 KB |
Output is correct |
2 |
Correct |
0 ms |
1672 KB |
Output is correct |
3 |
Correct |
0 ms |
1672 KB |
Output is correct |
4 |
Correct |
8 ms |
1672 KB |
Output is correct |
5 |
Correct |
0 ms |
1672 KB |
Output is correct |
6 |
Correct |
8 ms |
1672 KB |
Output is correct |
7 |
Correct |
24 ms |
1844 KB |
Output is correct |
8 |
Correct |
28 ms |
1864 KB |
Output is correct |
9 |
Correct |
72 ms |
2060 KB |
Output is correct |
10 |
Correct |
68 ms |
2040 KB |
Output is correct |
11 |
Correct |
32 ms |
2060 KB |
Output is correct |
12 |
Correct |
24 ms |
2040 KB |
Output is correct |
13 |
Correct |
0 ms |
1672 KB |
Output is correct |
14 |
Correct |
4 ms |
1672 KB |
Output is correct |
15 |
Correct |
24 ms |
2052 KB |
Output is correct |