/// In The Name Of God
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define nl '\n'
#define ioi exit(0);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = (int)5e5 + 7, inf = (int)1e9 + 7, mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
int n;
ll ans;
int x[N], g[N];
ll d[N], s[N];
vector <ll> cmp;
int t[N << 2];
void upd(int p, int x, int v = 1, int tl = 0, int tr = n) {
if (tl == tr) {
t[v] = min(t[v], x);
return;
}
int tm = tl + tr >> 1;
if (p <= tm) upd(p, x, v << 1, tl, tm);
else upd(p, x, v << 1 | 1, tm + 1, tr);
t[v] = min(t[v << 1], t[v << 1 | 1]);
}
int get(int l, int r, int v = 1, int tl = 0, int tr = n) {
if (l <= tl && tr <= r) return t[v];
if (tl > r || tr < l) return inf;
int tm = tl + tr >> 1;
return min(get(l, r, v << 1, tl, tm), get(l, r, v << 1 | 1, tm + 1, tr));
}
int main() {
#ifdef IOI2018
freopen ("in.txt", "r", stdin);
#endif
Kazakhstan
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> s[i] >> d[i];
d[i] += d[i - 1];
s[i] += s[i - 1];
cmp.pb(x[i] - d[i - 1]);
}
sort(all(cmp));
cmp.erase(unique(all(cmp)), cmp.end());
memset(t, 0x3f, sizeof(t));
for (int i = 1; i <= n; i++) {
ll now = x[i] - d[i - 1];
upd(lower_bound(all(cmp), now) - cmp.begin(), i);
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
int p = get(lower_bound(all(cmp), x[i] - d[i]) - cmp.begin(), n);
if (p <= n) ans = max(ans, s[i] - s[p - 1]);
}
cout << ans;
ioi
}
Compilation message
divide.cpp: In function 'void upd(int, int, int, int, int)':
divide.cpp:47:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int tm = tl + tr >> 1;
^
divide.cpp: In function 'int get(int, int, int, int, int)':
divide.cpp:55:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int tm = tl + tr >> 1;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
21720 KB |
Output is correct |
2 |
Correct |
0 ms |
21720 KB |
Output is correct |
3 |
Correct |
0 ms |
21720 KB |
Output is correct |
4 |
Correct |
0 ms |
21720 KB |
Output is correct |
5 |
Correct |
0 ms |
21720 KB |
Output is correct |
6 |
Correct |
6 ms |
21720 KB |
Output is correct |
7 |
Correct |
0 ms |
21720 KB |
Output is correct |
8 |
Correct |
3 ms |
21720 KB |
Output is correct |
9 |
Correct |
3 ms |
21720 KB |
Output is correct |
10 |
Correct |
0 ms |
21720 KB |
Output is correct |
11 |
Correct |
0 ms |
21720 KB |
Output is correct |
12 |
Correct |
0 ms |
21720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
21720 KB |
Output is correct |
2 |
Correct |
3 ms |
21720 KB |
Output is correct |
3 |
Correct |
0 ms |
21720 KB |
Output is correct |
4 |
Correct |
0 ms |
21720 KB |
Output is correct |
5 |
Correct |
0 ms |
21720 KB |
Output is correct |
6 |
Correct |
0 ms |
21720 KB |
Output is correct |
7 |
Correct |
3 ms |
21720 KB |
Output is correct |
8 |
Correct |
3 ms |
21720 KB |
Output is correct |
9 |
Correct |
3 ms |
21720 KB |
Output is correct |
10 |
Correct |
0 ms |
21720 KB |
Output is correct |
11 |
Correct |
6 ms |
21880 KB |
Output is correct |
12 |
Correct |
3 ms |
21880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
21880 KB |
Output is correct |
2 |
Correct |
13 ms |
21880 KB |
Output is correct |
3 |
Correct |
3 ms |
21880 KB |
Output is correct |
4 |
Correct |
36 ms |
22528 KB |
Output is correct |
5 |
Correct |
36 ms |
22528 KB |
Output is correct |
6 |
Correct |
86 ms |
23296 KB |
Output is correct |
7 |
Correct |
73 ms |
23296 KB |
Output is correct |
8 |
Correct |
83 ms |
23296 KB |
Output is correct |
9 |
Correct |
76 ms |
23296 KB |
Output is correct |
10 |
Correct |
73 ms |
23296 KB |
Output is correct |
11 |
Correct |
66 ms |
23296 KB |
Output is correct |
12 |
Correct |
69 ms |
23296 KB |
Output is correct |