#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int n, l, x[N], g[N], e[N];
ll de[N], dg[N], ans;
set < pair < ll, int > > st;
int main() {
// freopen("divide.in", "r", stdin);
// freopen("divide.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n + 1; ++i) {
if (i != n + 1) {
cin >> x[i] >> g[i] >> e[i];
dg[i] += dg[i - 1] + g[i];
de[i] += de[i - 1] + e[i];
}
ans = max(ans, 1ll * g[i]);
if (i > 1) {
int l = st.begin()->second;
if (x[i] - x[l] <= de[i] - de[l - 1] && dg[i] - dg[l - 1] > ans) {
ans = dg[i] - dg[l - 1];
}
}
st.insert({dg[i], i});
}
// for (int l = 1; l <= n; ++l) {
// for (int r = l; r <= n; ++r) {
// if (x[r] - x[l] <= de[r] - de[l - 1] && dg[r] - dg[l - 1] > ans) {
// ans = dg[r] - dg[l - 1];
// }
// }
// }
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4752 KB |
Output is correct |
2 |
Incorrect |
0 ms |
4752 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4752 KB |
Output is correct |
2 |
Correct |
0 ms |
4752 KB |
Output is correct |
3 |
Incorrect |
0 ms |
4752 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5016 KB |
Output is correct |
2 |
Correct |
9 ms |
5412 KB |
Output is correct |
3 |
Correct |
9 ms |
5412 KB |
Output is correct |
4 |
Correct |
66 ms |
7920 KB |
Output is correct |
5 |
Correct |
83 ms |
7920 KB |
Output is correct |
6 |
Correct |
186 ms |
10956 KB |
Output is correct |
7 |
Correct |
139 ms |
10956 KB |
Output is correct |
8 |
Correct |
146 ms |
10956 KB |
Output is correct |
9 |
Correct |
146 ms |
10956 KB |
Output is correct |
10 |
Incorrect |
139 ms |
10956 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |