#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll INF = 1'000'000'000'000'000'000LL;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
ll x[1+N], g[1+N], d[1+N];
d[0] = 0;
g[0] = 0;
for(int i = 1; i <= N; i++)
{
cin >> x[i] >> g[i] >> d[i];
d[i] += d[i-1];
g[i] += g[i-1];
}
vector<pair<ll, ll> > A, B;
A.push_back({-INF, -INF});
B.push_back({-INF, -INF});
for(int i = 1; i <= N; i++)
{
A.push_back({d[i] - x[i], g[i]});
B.push_back({d[i-1] - x[i], - g[i-1]});
// cerr << i << " : " << d[i] - x[i] << "," << g[i] << " " << d[i-1]-x[i] << "," << -g[i-1] << '\n';
}
ll ans = 0;
sort(A.begin(), A.end());
sort(B.begin(), B.end());
ll sa = -INF, sb = -INF;
int a = 0, b = 0;
for(a = 1; a <= N; a++)
{
// sa = max(sa, A[a].second);
while(b+1 <= N && B[b+1].first <= A[a].first)
{
b++;
sb = max(sb, B[b].second);
}
ans = max(ans, A[a].second+sb);
}
cout << ans << '\n';
}
Compilation message
divide.cpp: In function 'int main()':
divide.cpp:45:8: warning: unused variable 'sa' [-Wunused-variable]
45 | ll sa = -INF, sb = -INF;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
308 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
308 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
460 KB |
Output is correct |
23 |
Correct |
3 ms |
708 KB |
Output is correct |
24 |
Correct |
3 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
308 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
460 KB |
Output is correct |
23 |
Correct |
3 ms |
708 KB |
Output is correct |
24 |
Correct |
3 ms |
716 KB |
Output is correct |
25 |
Correct |
2 ms |
704 KB |
Output is correct |
26 |
Correct |
4 ms |
1096 KB |
Output is correct |
27 |
Correct |
3 ms |
1068 KB |
Output is correct |
28 |
Correct |
16 ms |
3288 KB |
Output is correct |
29 |
Correct |
18 ms |
4520 KB |
Output is correct |
30 |
Correct |
39 ms |
8864 KB |
Output is correct |
31 |
Correct |
30 ms |
7712 KB |
Output is correct |
32 |
Correct |
32 ms |
7720 KB |
Output is correct |
33 |
Correct |
37 ms |
7592 KB |
Output is correct |
34 |
Correct |
33 ms |
7596 KB |
Output is correct |
35 |
Correct |
36 ms |
8088 KB |
Output is correct |
36 |
Correct |
34 ms |
8240 KB |
Output is correct |