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 <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;
}
long long int findMaxAttraction(int n, int start, int d, int attraction[])
{
if (start == 0)
return fromZero(n, d, attraction);
long long int ans = 0;
for (int l = start; l >= 0; l--)
{
for (int r = start; r < n; r++)
{
// l ~ r 구간
int use = r - l + min(r - start, start - l);
int remain = d - use;
vector<int> at;
for (int i = l; i <= r; i++)
at.push_back(attraction[i]);
sort(all(at), greater<int>());
long long int now = 0;
for (int i = 0; i < min<int>(remain, at.size()); i++)
now += at[i];
ans = max(ans, now);
}
}
return ans;
}
Compilation message (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)
~~~~~~~~~^~~~~~~~~~
# | 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... |