이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"holiday.h"
#include "bits/stdc++.h"
long long frontR[100010];
long long frontB[100010];
long long backR[100010];
long long backB[100010];
std :: vector <int> P, Q;
long long sortSum(std :: vector <int> &v, int x, int take) {
if(take < 0) return 0;
std :: priority_queue <int, std :: vector <int>, std :: greater <int> > q;
long long ans = 0;
for(int i = 0; i <= x; i++) {
q.push(v[i]);
ans += v[i];
while(q.size() > take) {
ans -= q.top();
q.pop();
}
}
return ans;
}
void solveFront(int l, int r, int b, int e) {
if(l > r) return ;
int m = (l + r) >> 1;
int opt = b;
long long best = -1;
for(int i = b; i <= e; i++) {
long long o = sortSum(P, i, m - (i + 1));
if(o > best) {
best = o;
opt = i;
}
}
solveFront(l, m - 1, b, opt);
solveFront(m + 1, r, opt, e);
frontR[m] = std :: max(frontR[m], best);
}
void frontCal(int d) {
frontB[d] = frontR[d] = 0;
std :: priority_queue <int, std :: vector <int>, std :: greater <int> > q;
int take = 0;
long long ans = 0;
for(size_t i = 0; i < P.size(); i++) {
take += 2;
if(take > d) break;
q.push(P[i]);
ans += P[i];
while(q.size() + take > d) {
ans -= q.top();
q.pop();
}
frontB[d] = std :: max(frontB[d], ans);
}
}
void backCal(int d) {
backB[d] = backR[d] = 0;
std :: priority_queue <int, std :: vector <int>, std :: greater <int> > q;
int take = 0;
long long ans = 0;
for(size_t i = 0; i < Q.size(); i++) {
++take;
if(take > d) break;
q.push(Q[i]);
ans += Q[i];
while(q.size() + take > d) {
ans -= q.top();
q.pop();
}
backR[d] = std :: max(backR[d], ans);
}
take = 0;
ans = 0;
while(!q.empty()) q.pop();
for(size_t i = 0; i < Q.size(); i++) {
take += 2;
if(take > d) break;
q.push(Q[i]);
ans += Q[i];
while(q.size() + take > d) {
ans -= q.top();
q.pop();
}
backB[d] = std :: max(backB[d], ans);
}
}
long long int findMaxAttraction(int n, int start, int d, int attraction[]) {
for(int i = 0; i < start; i++) {
P.push_back(attraction[i]);
}
for(int i = start + 1; i < n; i++) {
Q.push_back(attraction[i]);
}
std :: reverse(P.begin(), P.end());
for(size_t i = 0; i <= d; i++) {
frontCal(i);
backCal(i);
}
if(!P.empty()) solveFront(1, d, 0, P.size() - 1);
long long ans = 0;
for(int i = 0; i < d; i++) {
ans = std :: max(ans, frontB[i] + attraction[start] + backR[d - i - 1]);
ans = std :: max(ans, frontR[d - i - 1] + attraction[start] + backB[i]);
}
for(int i = 0; i <= d; i++) {
ans = std :: max(ans, frontB[i] + backR[d - i]);
ans = std :: max(ans, frontR[d - i] + backB[i]);
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
holiday.cpp: In function 'long long int sortSum(std::vector<int>&, int, int)':
holiday.cpp:16:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(q.size() > take) {
^
holiday.cpp: In function 'void frontCal(int)':
holiday.cpp:50:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(q.size() + take > d) {
^
holiday.cpp: In function 'void backCal(int)':
holiday.cpp:70:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(q.size() + take > d) {
^
holiday.cpp:87:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(q.size() + take > d) {
^
holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:104:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(size_t i = 0; i <= d; i++) {
^
grader.cpp: In function 'int main()':
grader.cpp:7:12: warning: variable 'n_s' set but not used [-Wunused-but-set-variable]
int i, n_s;
^
# | 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... |