Submission #4111

#TimeUsernameProblemLanguageResultExecution timeMemory
4111jaysKing of penalty (kriii1_K)C++98
0 / 1
20 ms1624 KiB
#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 timeMemoryGrader output
Fetching results...