# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
261453 | A02 | Holiday (IOI14_holiday) | C++14 | 5084 ms | 2300 KiB |
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 <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <utility>
#include <set>
#include <queue>
using namespace std;
long long int findMaxAttraction(int n, int start, int d, int attraction[]) {
if (d == 0){
return 0;
}
if (start == 0){
long long total = 0;
int can_visit = d;
priority_queue<long long> best;
long long best_sum = 0;
for (int i = 0; i <= 0; i++){
best.push(-attraction[i]);
best_sum += attraction[i];
}
while (best.size() > can_visit){
best_sum -= -best.top();
best.pop();
}
int right = start;
total = max(total, best_sum);
while (can_visit > 1 && right < n - 1){
can_visit -= 1;
right++;
best.push(-attraction[right]);
best_sum += attraction[right];
while (best.size() > can_visit){
best_sum -= -best.top();
best.pop();
}
total = max(total, best_sum);
}
return total;
}
long long total = 0;
for (int left = start; left >= 0 && start - left < d; left--){
int can_visit = d - (start - left);
priority_queue<long long> best;
long long best_sum = 0;
for (int i = left; i <= start; i++){
best.push(-attraction[i]);
best_sum += attraction[i];
}
while (best.size() > can_visit){
best_sum -= -best.top();
best.pop();
}
int right = start;
total = max(total, best_sum);
while (can_visit > 2 && right < n - 1){
can_visit -= 2;
right++;
best.push(-attraction[right]);
best_sum += attraction[right];
while (best.size() > can_visit){
best_sum -= -best.top();
best.pop();
}
total = max(total, best_sum);
}
}
for (int right = start; right < n && right - start < d; right++){
int can_visit = d - (right - start);
priority_queue<long long> best;
long long best_sum = 0;
for (int i = start; i <= right; i++){
best.push(-attraction[i]);
best_sum += attraction[i];
}
while (best.size() > can_visit){
best_sum -= -best.top();
best.pop();
}
int left = start;
total = max(total, best_sum);
while (can_visit > 2 && left > 0){
can_visit -= 2;
left--;
best.push(-attraction[left]);
best_sum += attraction[left];
while (best.size() > can_visit){
best_sum -= -best.top();
best.pop();
}
total = max(total, best_sum);
}
}
return total;
}
Compilation message (stderr)
# | 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... |