이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"holiday.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll findMaxFrom(int n, int start, int d, int attraction[]){
//from start
int numwalk = d/2;
int numtake = d-numwalk;
priority_queue<ll,vector<ll>,greater<ll>> pq;
ll tot = 0;
ll ans = 0;
for (int i = start; i<=min(n-1,start+numwalk); i++){
tot+=attraction[i];
pq.push(attraction[i]);
}
if (numtake==numwalk&&start+numwalk<=n-1){
tot-=pq.top();
pq.pop();
}
ans=max(ans,tot);
int cur = start+numwalk;
while (cur<n-1&&numtake>0&&numwalk<d){
//walk one more
numtake--;
numwalk++;
cur++;
tot+=attraction[cur];
pq.push(attraction[cur]);
tot-=pq.top();
pq.pop();
tot-=pq.top();
pq.pop();
ans=max(ans,tot);
}
return ans;
}
ll findMaxAttraction(int n, int start, int d, int attraction[]) {
ll mx = 0;
for (int i = max(0,start-d); i<=start; i++){
mx=max(mx,findMaxFrom(n,i,d-(start-i),attraction));
}
if (n>5000){
return mx;
}
reverse(attraction,attraction+n);
start=n-1-start;
for (int i = max(0,start-d); i<=start; i++){
mx=max(mx,findMaxFrom(n,i,d-(start-i),attraction));
}
return mx;
}
# | 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... |