# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
3602 | sjw0687 | King of penalty (kriii1_K) | C++98 | 64 ms | 2844 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 <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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |