# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95426 | choikiwon | Divide and conquer (IZhO14_divide) | C++17 | 59 ms | 10196 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>
using namespace std;
typedef long long ll;
const int MN = 100010;
int N;
int X[MN], G[MN], E[MN];
ll esum[MN], gsum[MN];
vector<pair<ll, int> > ord1, ord2;
priority_queue<int> pq;
int main() {
scanf("%d", &N);
for(int i = 0; i < N; i++) {
scanf("%d %d %d", &X[i], &G[i], &E[i]);
}
for(int i = 0; i < N; i++) {
esum[i] = E[i];
gsum[i] = G[i];
if(i) {
esum[i] += esum[i - 1];
gsum[i] += gsum[i - 1];
}
}
for(int i = 0; i < N; i++) {
ord1.push_back({ (i? esum[i - 1] : 0) - X[i], i });
ord2.push_back({ esum[i] - X[i], i });
}
sort(ord1.begin(), ord1.end());
sort(ord2.begin(), ord2.end());
int pos = (int)ord2.size() - 1;
ll ans = 0;
for(int i = (int)ord1.size() - 1; i >= 0; i--) {
while(pos >= 0 && ord2[pos].first >= ord1[i].first) {
pq.push(ord2[pos--].second);
}
int x = ord1[i].second;
if(!pq.empty() && pq.top() >= x) {
ans = max(ans, gsum[ pq.top() ] - (x? gsum[x - 1] : 0));
}
}
printf("%lld", ans);
}
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... |