이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define NAME "task"
#define int long long
const int N = 1e5 + 5;
int n,s,d,a[N],ans = 0;
namespace sub2 {
void solve() {
priority_queue<int,vector<int>,greater<int>>q;
int cur = 0;
for (int i = 0; i < n; i++) {
q.push(a[i]);
cur += a[i];
while (!q.empty() && i + q.size() > d) {
cur -= q.top();
q.pop();
}
ans = max(ans,cur);
}
//cout << ans << "\n";
}
}
namespace sub3 {
void solve() {
for (int i = s; i >= 0; i--) {
if (s - i > d) break;
priority_queue<int,vector<int>,greater<int>>q;
int j = s,cur = 0;
while (j >= i) {
q.push(a[j]);
cur += a[j];
while (!q.empty() && s - j + q.size() > d) {
cur -= q.top();
q.pop();
}
ans = max(ans,cur);
j--;
}
j = s + 1;
while (j < n) {
q.push(a[j]);
cur += a[j];
while (!q.empty() && s - i + j - i + q.size() > d) {
cur -= q.top();
q.pop();
}
ans = max(ans,cur);
j++;
}
}
reverse(a,a + n);
s = n - s - 1;
for (int i = s; i >= 0; i--) {
if (s - i > d) break;
priority_queue<int,vector<int>,greater<int>>q;
int j = s,cur = 0;
while (j >= i) {
q.push(a[j]);
cur += a[j];
while (!q.empty() && s - j + q.size() > d) {
cur -= q.top();
q.pop();
}
ans = max(ans,cur);
j--;
}
j = s + 1;
while (j < n) {
q.push(a[j]);
cur += a[j];
while (!q.empty() && s - i + j - i + q.size() > d) {
cur -= q.top();
q.pop();
}
ans = max(ans,cur);
j++;
}
}
//cout << ans << "\n";
}
}
int findMaxAttraction(int32_t N, int32_t S, int32_t D, int32_t attraction[]) {
s = S;
d = D;
n = N;
for (int i = 0; i < n; i++) a[i] = attraction[i];
if (s == 0) sub2::solve();
else if (n <= 3e3) sub3::solve();
return ans;
}
/*signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen(NAME".inp","r",stdin);
freopen(NAME".out","w",stdout);
cin >> n >> s >> d;
for (int i = 0; i < n; i++) cin >> a[i];
if (s == 0) sub2::solve();
else if (n <= 3e3) sub3::solve();
}*/
컴파일 시 표준 에러 (stderr) 메시지
holiday.cpp: In function 'void sub2::solve()':
holiday.cpp:17:47: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
17 | while (!q.empty() && i + q.size() > d) {
| ~~~~~~~~~~~~~^~~
holiday.cpp: In function 'void sub3::solve()':
holiday.cpp:36:55: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
36 | while (!q.empty() && s - j + q.size() > d) {
| ~~~~~~~~~~~~~~~~~^~~
holiday.cpp:47:63: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
47 | while (!q.empty() && s - i + j - i + q.size() > d) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
holiday.cpp:64:55: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
64 | while (!q.empty() && s - j + q.size() > d) {
| ~~~~~~~~~~~~~~~~~^~~
holiday.cpp:75:63: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
75 | while (!q.empty() && s - i + j - i + q.size() > d) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
# | 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... |