# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
679338 | Cross_Ratio | Holiday (IOI14_holiday) | C++14 | 5063 ms | 1904 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 <bits/stdc++.h>
#include "holiday.h"
using namespace std;
typedef long long ll;
int N, st, d;
int A[100005];
typedef pair<int, int> P;
ll findMaxAttraction(int _N, int _st, int _d, int attraction[]) {
N = _N, st = _st, d = _d;
int i, j;
for(i=0;i<N;i++) A[i] = attraction[i];
ll ans = 0;
ll sum = 0;
for(i=st;i>=0;i--) {
int val = d;
val -= 2*(st - i);
if(val <= 0) break;
priority_queue<int, vector<int>, greater<int>> PQ;
ll cnt = 0;
for(int j = i; j <= st; j++) {
cnt += A[j];
PQ.push(A[j]);
while(PQ.size()>val) {
cnt -= PQ.top();
PQ.pop();
}
}
ans = max(ans, cnt);
for(j=st+1;j<N;j++) {
cnt += A[j];
PQ.push(A[j]);
val--;
if(val <= 0) break;
while(PQ.size()>val) {
cnt -= PQ.top();
PQ.pop();
}
ans = max(ans, cnt);
}
}
if(st==0) return ans;
st = N-1-st;
reverse(A, A+N);
for(i=st;i>=0;i--) {
int val = d;
val -= 2*(st - i);
if(val <= 0) break;
priority_queue<int, vector<int>, greater<int>> PQ;
ll cnt = 0;
for(int j = i; j <= st; j++) {
cnt += A[j];
PQ.push(A[j]);
while(PQ.size()>val) {
cnt -= PQ.top();
PQ.pop();
}
}
ans = max(ans, cnt);
for(j=st+1;j<N;j++) {
cnt += A[j];
PQ.push(A[j]);
val--;
if(val <= 0) break;
while(PQ.size()>val) {
cnt -= PQ.top();
PQ.pop();
}
ans = max(ans, cnt);
}
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |