이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |