이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n;
int st;
int d;
long long arr[100000];
long long findMaxAttraction(int nn,int start,int dd,int at[]) {
n=nn;
st=start;
d=dd;
for(int i=0;i<n;i++) {
arr[i]=at[i];
}
long long ret=0;
long long sum=0;
priority_queue<long long,vector<long long>,greater<long long>> pq;
for(int i=st;i>=0;i--) {
pq.push(arr[i]);
sum+=arr[i];
while ((int)pq.size()>d-st+i&&!pq.empty()) {
sum-=pq.top();
pq.pop();
}
ret=max(ret,sum);
}
while (!pq.empty()) {
pq.pop();
}
sum=0;
for(int i=st;i<n;i++) {
pq.push(arr[i]);
sum+=arr[i];
while ((int)pq.size()>d-i+st&&!pq.empty()) {
sum-=pq.top();
pq.pop();
}
ret=max(ret,sum);
}
if (st==0||st==n-1) {
return ret;
}
for(int i=st;i>=0;i--) {
while (!pq.empty()) {
pq.pop();
}
sum=0;
for(int j=i;j<n;j++) {
pq.push(arr[j]);
sum+=arr[j];
while ((int)pq.size()>d-st-j+2*i&&!pq.empty()) {
sum-=pq.top();
pq.pop();
}
ret=max(ret,sum);
}
}
for(int i=st;i<n;i++) {
while (!pq.empty()) {
pq.pop();
}
sum=0;
for(int j=i;j>=0;j--) {
pq.push(arr[j]);
sum+=arr[j];
while ((int)pq.size()>d+j+st-2*i&&!pq.empty()) {
sum-=pq.top();
pq.pop();
}
}
ret=max(ret,sum);
}
return ret;
}
# | 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... |