Submission #3403

#TimeUsernameProblemLanguageResultExecution timeMemory
3403wookayinKing of penalty (kriii1_K)C++98
1 / 1
72 ms2060 KiB
#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 timeMemoryGrader output
Fetching results...