#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <assert.h>
#include <numeric>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 100007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
ll n, x[M], g[M], d[M], seg[4 * M], lazy[4 * M], ans;
void push(int node, int l, int r)
{
if(lazy[node] != 0){
seg[node] += (r - l + 1) * lazy[node];
if(l != r){
lazy[2 * node] += lazy[node];
lazy[2 * node + 1] += lazy[node];
}
lazy[node] = 0;
}
return;
}
void upd(int st, int en, ll v, int node = 1, int l = 1, int r = n)
{
push(node, l, r);
if(l > en || r < st) return;
if(l >= st && r <= en){
lazy[node] += v;
push(node, l, r);
return;
}
int mid = (l + r) / 2;
upd(st, en, v, 2 * node, l, mid);
upd(st, en, v, 2 * node + 1, mid + 1, r);
seg[node] = max(seg[2 * node], seg[2 * node + 1]);
return;
}
int get(int st, int en, int node = 1, int l = 1, int r = n)
{
push(node, l, r);
if(l > en || r < st || seg[node] < 0) return -1;
if(l == r) return l;
int mid = (l + r) / 2;
int ret = get(st, en, 2 * node + 1, mid + 1, r);
if(ret == -1) ret = get(st, en, 2 * node, l, mid);
return ret;
}
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; ++i){
scanf("%lld%lld%lld", &x[i], &g[i], &d[i]);
g[i] += g[i - 1];
d[i] += d[i - 1];
upd(i, i, d[i] - x[i]);
}
for(int i = 1; i <= n; ++i){
ll add = x[i] - x[i - 1];
if(i > 1) add += -d[i - 1] + d[i - 2];
upd(i, n, add);
ans = max(ans, g[get(i, n)] - g[i - 1]);
}
printf("%lld\n", ans);
return 0;
}
// Don't forget special cases. (n = 1?)
// Look for the constraints. (Runtime array? overflow?)
Compilation message
divide.cpp: In function 'int main()':
divide.cpp:71:13: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'll*' {aka 'long long int*'} [-Wformat=]
71 | scanf("%d", &n);
| ~^ ~~
| | |
| | ll* {aka long long int*}
| int*
| %lld
divide.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
divide.cpp:73:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | scanf("%lld%lld%lld", &x[i], &g[i], &d[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
4 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 |
9 ms |
428 KB |
Output is correct |
22 |
Correct |
16 ms |
436 KB |
Output is correct |
23 |
Correct |
93 ms |
588 KB |
Output is correct |
24 |
Correct |
104 ms |
708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
4 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 |
9 ms |
428 KB |
Output is correct |
22 |
Correct |
16 ms |
436 KB |
Output is correct |
23 |
Correct |
93 ms |
588 KB |
Output is correct |
24 |
Correct |
104 ms |
708 KB |
Output is correct |
25 |
Correct |
4 ms |
588 KB |
Output is correct |
26 |
Correct |
8 ms |
972 KB |
Output is correct |
27 |
Correct |
8 ms |
972 KB |
Output is correct |
28 |
Correct |
42 ms |
3460 KB |
Output is correct |
29 |
Correct |
43 ms |
3524 KB |
Output is correct |
30 |
Correct |
89 ms |
6672 KB |
Output is correct |
31 |
Correct |
82 ms |
6704 KB |
Output is correct |
32 |
Correct |
88 ms |
6740 KB |
Output is correct |
33 |
Correct |
81 ms |
6724 KB |
Output is correct |
34 |
Execution timed out |
1083 ms |
6688 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |