Submission #4112

#TimeUsernameProblemLanguageResultExecution timeMemory
4112jaysKing of penalty (kriii1_K)C++98
1 / 1
24 ms1980 KiB
#include <algorithm> #include <cstdio> #include <vector> typedef long long ll; using namespace std; int P, N; vector<int> pen; ll solve(int n) { ll ret = 0; int cp = P - 1; for (int i = 0; i < n; ++i) { ret += cp; cp -= pen[i]; } return ret; } int main() { scanf("%d%d", &P, &N); for (int i = 0; i < N; ++i) { int t; scanf("%d", &t); pen.push_back(t); } sort(pen.begin(), pen.end()); int sum = 0; for (int i = 0; i < pen.size(); ++i) { sum += pen[i]; if (sum >= P) { printf("%d %lld\n", i, solve(i)); return 0; } } printf("%d %lld\n", N, solve(N)); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...