# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
273323 | lookcook | Divide and conquer (IZhO14_divide) | C++17 | 3 ms | 2688 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 100005;
int psa[3][maxn]; // 0 = x, 1 = gold, 2 = energy
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < 3; i++) for (int j = 0; j < maxn; j++) psa[i][j] = 0;
int n;
cin >> n;
int last = 0;
int xs[n+1], gs[n+1], ds[n+1];
for (int i = 1; i <= n; i++) {
int x, g, d;
cin >> x >> g >> d;
xs[i] = x;
gs[i] = g;
ds[i] = d;
int tmp = x;
x -= last;
last = tmp;
psa[0][i] += x;
psa[1][i] += g;
psa[2][i] += d;
}
for (int i = 0; i < 3; i++) for (int j = 1; j < maxn; j++) psa[i][j] += psa[i][j-1];
int best = 0;
for (int l = 1; l <= n; l++) {
int pos = l;
for (int i = 17; i >= 0; i--) {
if (pos+(1<<i) < maxn && psa[0][pos+(1<<i)]-psa[0][l] <= psa[2][pos+(1<<i)]-psa[2][l-1]) {
pos += (1<<i);
}
}
int gold = psa[1][pos]-psa[1][l-1];
best = max(best, gold);
}
cout << best << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |