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"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;
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;
if(take > d) break;
q.push(P[i]);
ans += P[i];
while(q.size() + take > d) {
ans -= q.top();
q.pop();
}
frontR[d] = std :: max(frontR[d], ans);
}
take = 0;
ans = 0;
while(!q.empty()) q.pop();
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);
}
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;
}
Compilation message (stderr)
holiday.cpp: In function 'void frontCal(int)':
holiday.cpp:21:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(q.size() + take > d) {
^
holiday.cpp:36: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:56:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(q.size() + take > d) {
^
holiday.cpp:73: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:90: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... |