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 <iostream>
#include <queue>
#include <vector>
using namespace std;
int opposite[100001];
bool cmp(int a, int b){
return a > b;
}
long long solve_go_left(int n, int start, int d, int attraction[100000]){
priority_queue<int, vector<int>, decltype(&cmp)> heap(cmp);
long long sum = 0;
long long ans = 0;
for (int i = start;i >= max(0, start - d + 1);i--){
int num_days_left = d - (start - i);
if (heap.size() == num_days_left + 1){
sum -= heap.top();
heap.pop();
}
if (heap.size() == num_days_left){
if (heap.top() < attraction[i]){
sum -= heap.top();
heap.pop();
sum += attraction[i];
heap.push(attraction[i]);
}
}
else{
heap.push(attraction[i]);
sum += attraction[i];
}
if (sum > ans){
ans = sum;
}
}
return ans;
}
long long findMaxAttraction(int n, int start, int d, int attraction[100000]){
long long ans = solve_go_left(n, start, d, attraction);
for (int i = 0;i < n;i++){
opposite[n - 1 - i] = attraction[i];
}
ans = max(ans, solve_go_left(n, n - 1 - start, d, opposite));
for (int i = max(0, start - d + 1);i < start;i++){
ans = max(ans, solve_go_left(n, n - 1 - i, d - (start - i), opposite));
}
if (start != 0){
for (int i = start + 1; i <= min(n - 1, start + d - 1); i++) {
ans = max(ans, solve_go_left(n, i, d - (i - start), attraction));
}
}
return ans;
}
Compilation message (stderr)
holiday.cpp: In function 'long long int solve_go_left(int, int, int, int*)':
holiday.cpp:18:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, bool (*)(int, int)>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
18 | if (heap.size() == num_days_left + 1){
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
holiday.cpp:22:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, bool (*)(int, int)>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
22 | if (heap.size() == num_days_left){
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
# | 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... |