이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"holiday.h"
#include <queue>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
using namespace std;
long long int fromZero(int n, int d, int attraction[])
{
priority_queue<int, vector<int>, greater<int>> q;
long long int now = 0;
long long int ans = 0;
for (int i = 0; i < n; i++)
{
// 0 -> i까지 간다고 했을 때 관광지 방문에 쓸 수 있는 날짜
int canVisit = d - i;
now += attraction[i];
q.push(attraction[i]);
while (q.size() > canVisit)
{
now -= q.top();
q.pop();
}
ans = max(ans, now);
}
return ans;
}
// start -> l -> r 순으로 돌아다니는걸 가정
long long int solve(const vector<int> at, int start, int d)
{
long long int ans = 0;
int n = at.size();
for (int l = 0; l < n; l++)
{
priority_queue<int, vector<int>, greater<int>> used;
long long int now = 0;
int remain = d - (start - l);
for (int r = l; r < n && (r - l) <= remain; r++)
{
now += at[r];
used.push(at[r]);
while (used.size() > remain - (r - l))
{
now -= used.top();
used.pop();
}
ans = max(ans, now);
}
}
return ans;
}
long long int findMaxAttraction(int n, int start, int d, int attraction[])
{
if (start == 0)
return fromZero(n, d, attraction);
vector<int> at(n);
for (int i = 0; i < n; i++)
at[i] = attraction[i];
long long int ans = solve(at, start, d);
reverse(all(at));
start = n - 1 - start;
ans = max(ans, solve(at, start, d));
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
holiday.cpp: In function 'long long int fromZero(int, int, int*)':
holiday.cpp:23:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (q.size() > canVisit)
~~~~~~~~~^~~~~~~~~~
holiday.cpp: In function 'long long int solve(std::vector<int>, int, int)':
holiday.cpp:53:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (used.size() > remain - (r - l))
~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# | 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... |