이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
#define pb push_back
#define ff first
#define ss second
ll get(vector<int> a, int n, int x, int d){
auto f = [&](int l, int r){
int f = d - (x - l) - (r - l);
vector<int> p;
for (int i = l; i <= r; i++){
p.pb(a[i]);
}
sort(p.begin(), p.end(), greater<int>());
ll sum = 0;
for (int i = 0; i < min(f, (int) p.size()); i++){
sum += p[i];
}
return sum;
};
ll out = 0;
function<void(int, int, int, int)> solve = [&](int l, int r, int l1, int r1){
if (l > r) return;
int m = (l + r) / 2;
pli mx = {-1, 0};
for (int i = l1; i <= r1; i++){
mx = max(mx, {f(m, i), -i});
}
out = max(out, mx.ff);
mx.ss = -mx.ss;
solve(l, m - 1, l1, mx.ss);
solve(m + 1, r, mx.ss, r1);
};
solve(1, x, x, n);
return out;
}
ll findMaxAttraction(int n, int x, int d, int A[]){
vector<int> a(n + 1);
for (int i = 1; i <= n; i++){
a[i] = A[i - 1];
}
x++;
ll out = get(a, n, x, d);
reverse(a.begin() + 1, a.end());
out = max(out, get(a, n, x, d));
return out;
}
# | 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... |