# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
using namespace std;
const ll INF = 8e18 + 10;
const ll MOD = 1e9 + 7;
const int N = 1e5 + 10;
const int Z = 5e4 + 10;
ll n;
ll x[N], g[N], e[N], pf[N], ans;
void solve()
{
cin >> n;
for (int i = 1; i <= n; i++){
cin >> x[i] >> g[i] >> e[i];
g[i] += g[i - 1];
e[i] += e[i - 1];
pf[i] = min(pf[i - 1], e[i - 1] - x[i]);
//cout << pf[i] << ' ';
}
for (int i = 1; i <= n; i++){
int l = 1, m, r = i;
ans = max(ans, g[i] - g[i - 1]);
while(r >= l){
m = (l + r) >> 1;
if(pf[m] <= e[i] - x[i]){
ans = max(ans, g[i] - g[m - 1]);
r = m - 1;
}
else
l = m + 1;
}
}
cout << ans;
}
int main()
{
int TE = 1;
ios_base::sync_with_stdio(false);
//freopen("sort.in", "r", stdin);
//freopen("sort.out", "w", stdout);
//cin >> TE;
while(TE --)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
444 KB |
Output is correct |
3 |
Correct |
2 ms |
444 KB |
Output is correct |
4 |
Correct |
2 ms |
444 KB |
Output is correct |
5 |
Correct |
2 ms |
524 KB |
Output is correct |
6 |
Correct |
2 ms |
524 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
2 ms |
620 KB |
Output is correct |
10 |
Correct |
2 ms |
620 KB |
Output is correct |
11 |
Correct |
2 ms |
620 KB |
Output is correct |
12 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
644 KB |
Output is correct |
3 |
Correct |
2 ms |
648 KB |
Output is correct |
4 |
Correct |
2 ms |
668 KB |
Output is correct |
5 |
Correct |
2 ms |
668 KB |
Output is correct |
6 |
Correct |
2 ms |
688 KB |
Output is correct |
7 |
Correct |
2 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
744 KB |
Output is correct |
9 |
Correct |
2 ms |
764 KB |
Output is correct |
10 |
Correct |
2 ms |
1072 KB |
Output is correct |
11 |
Correct |
3 ms |
1100 KB |
Output is correct |
12 |
Correct |
3 ms |
1212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1212 KB |
Output is correct |
2 |
Correct |
4 ms |
1324 KB |
Output is correct |
3 |
Correct |
4 ms |
1324 KB |
Output is correct |
4 |
Correct |
17 ms |
2604 KB |
Output is correct |
5 |
Correct |
19 ms |
2660 KB |
Output is correct |
6 |
Correct |
40 ms |
4140 KB |
Output is correct |
7 |
Correct |
33 ms |
4144 KB |
Output is correct |
8 |
Correct |
33 ms |
4144 KB |
Output is correct |
9 |
Correct |
31 ms |
4268 KB |
Output is correct |
10 |
Correct |
31 ms |
4268 KB |
Output is correct |
11 |
Correct |
35 ms |
6444 KB |
Output is correct |
12 |
Correct |
36 ms |
8808 KB |
Output is correct |