이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"holiday.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100100;
int n, a[N];
ll suff[N];
long long int findMaxAttraction(int n, int start, int d, int attraction[]) {
::n = n;
for (int i = 1; i <= n; i++)
a[i] = attraction[i-1];
++start;
if (start == 1){
ll ans = 0;
multiset<int> q;
int curd = 0;
ll sum = 0;
for (int i = 1; i <= n; i++){
++curd;
q.insert(a[i]);
sum += a[i];
while(!q.empty() && curd > d){
sum -= *q.begin();
q.erase(q.begin());
--curd;
}
if (curd <= d){
ans = max(ans, sum);
}
++curd;
}
return ans;
}
ll ans = 0;
++d;
for (int i = start; i >= 1; i--){
vector <int> vec;
for (int j = i; j <= n; j++){
vec.push_back(a[j]);
}
sort(vec.begin(), vec.end());
for (int j = i; j <= n; j++){
suff[j] = suff[j-1] + vec[j-i];
}
for (int j = i; j <= n; j++){
int curd = abs(start-i)*2+abs(start-j);
int sz = min(j-i+1, d-curd);
if (sz <= 0)
break;
if (start <= j)
ans = max(ans, suff[j]-suff[j-sz]);
}
}
reverse(a+1, a+n+1);
start = n-start+1;
for (int i = start; i >= 1; i--){
vector <int> vec;
for (int j = i; j <= n; j++){
vec.push_back(a[j]);
}
sort(vec.begin(), vec.end());
for (int j = i; j <= n; j++){
suff[j] = suff[j-1] + vec[j-i];
}
for (int j = i; j <= n; j++){
int curd = abs(start-i)*2+abs(start-j);
int sz = min(j-i+1, d-curd);
if (sz <= 0)
break;
if (start <= j)
ans = max(ans, suff[j]-suff[j-sz]);
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
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... |