이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "holiday.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e5 + 5;
int n, a[maxn];
int solve(int S, int d) {
int ans = 0, curans = 0;
priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
for (int i=S;i<=n;i++) {
pq.push({a[i], -i}), curans += a[i];
while (pq.size() > 0 && i-S + pq.size() > d) {
curans -= pq.top().first;
pq.pop();
}
ans = max(curans, ans);
}
while (pq.size() > 0) pq.pop();
curans = 0;
priority_queue<int> pq2;
bool del[n+1];
for (int i=1;i<=n;i++) del[i] = false;
for (int i=S;i<=n;i++) {
pq.push({a[i], -i}), pq2.push(i), curans += a[i];
while (pq.size() > 0 && i-S + pq.size() > d) {
pair<int,int> x = pq.top();
curans -= x.first;
del[-x.second] = true;
pq.pop();
}
if (curans==ans) break;
}
while (pq2.size() > 0) {
int X = pq2.top();
if (del[X]) pq2.pop(), del[X] = false;
else break;
}
for (int i=S-1, D = d-1; i>=1 && D>=1; i--, D--) {
pq.push({a[i], -i}), pq2.push(i), curans += a[i];
while (pq.size() > 0 && pq2.top()-i + pq.size() > D) {
pair<int,int> x = pq.top();
curans -= x.first;
pq.pop();
del[-x.second] = true;
while (pq2.size() > 0) {
int X = pq2.top();
if (del[X]) pq2.pop(), del[X] = false;
else break;
}
}
ans = max(curans, ans);
}
return ans;
}
int findMaxAttraction(int32_t N, int32_t S, int32_t D, int32_t A[]) {
n = N, S++;
for (int i=1;i<=n;i++) a[i] = A[i-1];
int ans1 = solve(S, D);
reverse(a+1, a+n+1); S = n+1-S;
int ans2 = solve(S, D);
return max(ans1, ans2);
}
컴파일 시 표준 에러 (stderr) 메시지
holiday.cpp: In function 'long long int solve(long long int, long long int)':
holiday.cpp:13:49: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
13 | while (pq.size() > 0 && i-S + pq.size() > d) {
| ~~~~~~~~~~~~~~~~^~~
holiday.cpp:26:49: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
26 | while (pq.size() > 0 && i-S + pq.size() > d) {
| ~~~~~~~~~~~~~~~~^~~
holiday.cpp:42:57: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
42 | while (pq.size() > 0 && pq2.top()-i + pq.size() > D) {
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~
# | 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... |