Submission #3602

#TimeUsernameProblemLanguageResultExecution timeMemory
3602sjw0687King of penalty (kriii1_K)C++98
1 / 1
64 ms2844 KiB
#include <cstdio> #include <iostream> #include <cstdlib> #include <cstring> #include <cmath> #include <climits> #include <algorithm> #include <utility> #include <string> #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> using namespace std; typedef long long llong; int p, n; int timeProb[100001]; llong sumT[100001]; int numSolve; int main(void) { cin >> p >> n; for(int i=1; i<=n; i++) { cin >> timeProb[i]; } sort(timeProb+1, timeProb+(n+1)); for(int i=1; i<=n; i++) { sumT[i] = sumT[i-1] + timeProb[i]; if( sumT[i] < p ) numSolve = i; } llong tAnswer = 0; for(int i=1; i <= n - numSolve + 1; i++) { int first = i; int last = i+numSolve-1; llong totalT = sumT[last] - sumT[first-1]; llong preT = p - totalT - 1; if( totalT >= p ) break; llong t = 0; t += preT * numSolve; for(int j=last; j>=first; j--) { llong cnt = j - first + 1; t += cnt * timeProb[j]; } if( t > tAnswer ) tAnswer = t; } cout << numSolve << ' ' << tAnswer << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...