이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "holiday.h"
using namespace std;
using ll = long long;
const int N = 100010;
int lastbest = N;
ll solve(int att[], int n, int d)
{
ll ans = 0, sum = 0;
priority_queue<int, vector<int>, greater<int>> val;
int bestix = 0;
for (int i = 0; i < n && d > 0; ++i, --d) {
val.push(att[i]);
sum += att[i];
while (val.size() > d) {
sum -= val.top();
val.pop();
}
if (sum > ans)
bestix = i;
ans = max(ans, sum);
}
assert(bestix <= lastbest+1); // FOR TESTING
lastbest = bestix;
return ans;
}
ll findMaxAttraction(int n, int start, int d, int att[])
{
if (n > 3000 && start > 0)
return -1;
ll ans = 0;
for (int i = 0; i <= start; ++i)
ans = max(ans, solve(&att[start-i], n-start+i, d-i));
if (start > 0) {
start = n-start-1;
reverse(att, att+n);
for (int i = 0; i <= start; ++i)
ans = max(ans, solve(&att[start-i], n-start+i, d-i));
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
holiday.cpp: In function 'll solve(int*, int, int)':
holiday.cpp:17:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (val.size() > d) {
~~~~~~~~~~~^~~
grader.cpp: In function 'int main()':
grader.cpp:7:12: warning: variable 'n_s' set but not used [-Wunused-but-set-variable]
int i, n_s;
^~~
# | 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... |