# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
4111 | jays | King of penalty (kriii1_K) | C++98 | 20 ms | 1624 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |