# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
173008 | tourist | Divide and conquer (IZhO14_divide) | C++14 | 7 ms | 1016 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 <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
#define sz(x) (int)x.size()
#define pii pair < int, int >
#define endl "\n"
#define METH ios::sync_with_stdio(0); cin.tie(0);
#define BEGIN cout << "BEGIN" << endl;
#define END cout << "END" << endl;
const int N = 1e5 + 9;
const int mod = 1e9 + 7; /// ANOTHER HASH MOD: 228228227
const int prime = 29; /// ANOTHER HASH PRIME: 997
const int INF = ((long long) 0xCAFEBABE - 1e9 - 4e8);
int n, g[N], en[N], suf[N];
vector < pii > eq;
vector < pair < int, pii > > v;
inline void read() {
scanf("%d", &n);
v.push_back({0, {0, 0}});
for (int i = 1; i <= n; i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
v.push_back({a, {b, c}});
en[i] = en[i - 1] + c;
eq.push_back({en[i] - a, i});
g[i] = g[i - 1] + b;
}
}
ll calc(int id) {
pii temp = {-(v[id].first - en[id - 1]), 0};
int index = lower_bound(eq.begin(), eq.end(), temp) - eq.begin();
return g[suf[index]] - g[id - 1];
}
inline void solve() {
ll ans = 0;
sort(eq.begin(), eq.end());
for (int i = n - 1; i >= 0; i--) {
suf[i] = max(suf[i + 1], eq[i].second);
}
for (int i = 1; i <= n; i++) {
ans = max(ans, calc(i));
}
cout << ans << endl;
}
int main() {
int t;
t = 1;
while (t--) {
read();
solve();
}
}
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... |