이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#if !defined(LOL)
#include "holiday.h"
#endif
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define ll long long
ll calc(deque<ll> &a, int d){
ll ans = 0, sum = 0;
multiset<ll> S; S.clear();
for(int i = 0; i < sz(a); i++){
S.insert(a[i]); sum+=(ll)a[i];
int rem = d-i; rem = max(rem,0);
while(sz(S)>rem) sum-=(ll)*S.begin(), S.erase(S.begin());
ans = max(ans, sum);
}
return ans;
}
long long int findMaxAttraction(int n, int s, int d, int a[]) {
deque<ll> v, w; for(int i = s; i < n; i++) v.pb(a[i]);
for(int i = 0; i <= s; i++) w.pb(a[i]); reverse(all(w));
ll ans = max(calc(v,d),calc(w,d));
for(int i = s-1; i>=0; i--){
v.push_front(a[i]),
ans = max(ans, calc(v,d-s+i));
}
if(s==0) return ans;
for(int i = s+1; i < n; i++){
w.push_front(a[i]),
ans = max(ans, calc(w,d-i+s));
}
return ans;
}
#if defined(LOL)
int main() {
int n, start, d;
int attraction[100000];
int i, n_s;
n_s = scanf("%d %d %d", &n, &start, &d);
for (i = 0 ; i < n; ++i) {
n_s = scanf("%d", &attraction[i]);
}
printf("%lld\n", findMaxAttraction(n, start, d, attraction));
return 0;
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:26:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
26 | for(int i = 0; i <= s; i++) w.pb(a[i]); reverse(all(w));
| ^~~
holiday.cpp:26:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
26 | for(int i = 0; i <= s; i++) w.pb(a[i]); reverse(all(w));
| ^~~~~~~
# | 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... |