#include <bits/stdc++.h>
#define fi(i, a, b) for( int i = a; i <= b; i++ )
#define fid(i, a, b) for( int i = a; i >= b; i-- )
#define getbit(x, i) ((x>>i)&1)
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define st first
#define nd second
#define mp make_pair
#define HTManh ""
#define maxn 100009
#define endl '\n'
using namespace std;
int n;
ll x[100009], g[100009], d[100009];
ll gt[100009];
map<ll, int> dich;
ll bit[100009];
void update(int vt, ll gt)
{
while(vt <= n)
{
bit[vt] = min(bit[vt], gt);
vt += (vt & -vt);
}
}
ll get(int vt)
{
ll s = 1e18;
while (vt > 0)
{
s = min(s, bit[vt]);
vt -= (vt & -vt);
}
return s;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL); cout.tie(NULL);
if (fopen(HTManh".inp", "r"))
{
freopen(HTManh".inp", "r", stdin);
freopen(HTManh".out", "w", stdout);
}
cin >> n;
fi(i,1,n) cin >> x[i] >> g[i] >> d[i];
fi(i,1,n) g[i] += g[i-1];
fi(i,1,n) d[i] += d[i-1];
fi(i,1,n) gt[i] = d[i-1] - x[i];
sort(gt+1,gt+n+1);
fi(i,1,n) dich[gt[i]] = i;
fi(i,1,n) bit[i] = 1e18;
ll res = 0;
fi(i,1,n)
{
update(dich[d[i-1]-x[i]], g[i-1]);
int dau = 1, cuoi = n;
while(dau <= cuoi)
{
int giua = (dau+cuoi)/2;
if (gt[giua] > d[i] - x[i]) cuoi = giua - 1;
else dau = giua + 1;
}
//cout << g[i] - get(cuoi) << endl;
res = max(res, g[i] - get(cuoi));
}
cout << res << endl;
}
Compilation message
divide.cpp: In function 'int main()':
divide.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | freopen(HTManh".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | freopen(HTManh".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2484 KB |
Output is correct |
4 |
Correct |
0 ms |
2516 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2484 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2484 KB |
Output is correct |
4 |
Correct |
0 ms |
2516 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2484 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2528 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2908 KB |
Output is correct |
24 |
Correct |
2 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2484 KB |
Output is correct |
4 |
Correct |
0 ms |
2516 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2484 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2528 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2908 KB |
Output is correct |
24 |
Correct |
2 ms |
2908 KB |
Output is correct |
25 |
Correct |
2 ms |
2908 KB |
Output is correct |
26 |
Correct |
4 ms |
3420 KB |
Output is correct |
27 |
Correct |
3 ms |
3420 KB |
Output is correct |
28 |
Correct |
20 ms |
7516 KB |
Output is correct |
29 |
Correct |
21 ms |
7772 KB |
Output is correct |
30 |
Correct |
46 ms |
13392 KB |
Output is correct |
31 |
Correct |
41 ms |
12116 KB |
Output is correct |
32 |
Correct |
39 ms |
12368 KB |
Output is correct |
33 |
Correct |
40 ms |
12124 KB |
Output is correct |
34 |
Correct |
40 ms |
12120 KB |
Output is correct |
35 |
Correct |
50 ms |
12884 KB |
Output is correct |
36 |
Correct |
41 ms |
12884 KB |
Output is correct |