#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 3e5+5;
const int M = (1<<17);
const ll inf = 1e15;
const ll mod = 1e15+7;
int n, t, k, m, d[N], in[N], out[N];
ll ans, tong, a[N], b[N], c[N];
string s[N];
struct node
{
int x[2];
set<int> vi;
node(){}
node( int _x, int _y)
{
x[0] = _x;
x[1] = _y;
}
};
vector<node> q;
vector<int> adj[N], kq;
void add(int x, int y)
{
for(int i = 0, j = 30; j >= 0; j --)
{
int t = (x >> j & 1);
if(q[i].x[t] == 0)
{
q[i].x[t] = q.size();
q.pb(node(0, 0));
}
i = q[i].x[t];
q[i].vi.insert(y);
}
}
int get(int x, int l, int r)
{
int total = 0;
for(int i = 0, j = 30; j >= 0; j --)
{
int t = (x >> j & 1);
int nxt = q[i].x[t^1];
auto it = q[nxt].vi.lower_bound(l);
if(it != q[nxt].vi.end() && (*it) <= r)
{
i = nxt;
total += (1<<j);
}
else i = q[i].x[t];
}
return total;
}
void dfs(int u)
{
in[u] = ++k;
for(int v: adj[u])dfs(v);
out[u] = k;
}
void sol()
{
cin >> n;
a[0] = inf;
for(int i = 1; i <= n; i ++)
{
cin >> d[i] >> b[i] >> c[i];
c[i] += c[i-1];
b[i] += b[i-1];
tong = c[i]-d[i];
int l = 1, r = i-1, mid;
while(l <= r)
{
mid = (l+r)>>1;
if(tong >= a[mid])r = mid-1;
else l = mid+1;
}
ans = max(ans, b[i]-b[r]);
a[i] = min(c[i-1]-d[i], a[i-1]);
}
cout << ans;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
#define task "test"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
Compilation message
divide.cpp: In function 'int main()':
divide.cpp:99:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:100:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
100 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
16772 KB |
Output is correct |
2 |
Correct |
12 ms |
16716 KB |
Output is correct |
3 |
Correct |
11 ms |
16744 KB |
Output is correct |
4 |
Correct |
9 ms |
16716 KB |
Output is correct |
5 |
Correct |
8 ms |
16784 KB |
Output is correct |
6 |
Correct |
9 ms |
16700 KB |
Output is correct |
7 |
Correct |
9 ms |
16796 KB |
Output is correct |
8 |
Correct |
12 ms |
16716 KB |
Output is correct |
9 |
Correct |
11 ms |
16788 KB |
Output is correct |
10 |
Correct |
9 ms |
16716 KB |
Output is correct |
11 |
Correct |
8 ms |
16764 KB |
Output is correct |
12 |
Correct |
8 ms |
16716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
16772 KB |
Output is correct |
2 |
Correct |
12 ms |
16716 KB |
Output is correct |
3 |
Correct |
11 ms |
16744 KB |
Output is correct |
4 |
Correct |
9 ms |
16716 KB |
Output is correct |
5 |
Correct |
8 ms |
16784 KB |
Output is correct |
6 |
Correct |
9 ms |
16700 KB |
Output is correct |
7 |
Correct |
9 ms |
16796 KB |
Output is correct |
8 |
Correct |
12 ms |
16716 KB |
Output is correct |
9 |
Correct |
11 ms |
16788 KB |
Output is correct |
10 |
Correct |
9 ms |
16716 KB |
Output is correct |
11 |
Correct |
8 ms |
16764 KB |
Output is correct |
12 |
Correct |
8 ms |
16716 KB |
Output is correct |
13 |
Correct |
8 ms |
16740 KB |
Output is correct |
14 |
Correct |
9 ms |
16716 KB |
Output is correct |
15 |
Correct |
8 ms |
16716 KB |
Output is correct |
16 |
Correct |
9 ms |
16832 KB |
Output is correct |
17 |
Correct |
9 ms |
16776 KB |
Output is correct |
18 |
Correct |
9 ms |
16844 KB |
Output is correct |
19 |
Correct |
9 ms |
16840 KB |
Output is correct |
20 |
Correct |
9 ms |
16844 KB |
Output is correct |
21 |
Correct |
9 ms |
16736 KB |
Output is correct |
22 |
Correct |
9 ms |
16844 KB |
Output is correct |
23 |
Correct |
10 ms |
16972 KB |
Output is correct |
24 |
Correct |
10 ms |
17032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
16772 KB |
Output is correct |
2 |
Correct |
12 ms |
16716 KB |
Output is correct |
3 |
Correct |
11 ms |
16744 KB |
Output is correct |
4 |
Correct |
9 ms |
16716 KB |
Output is correct |
5 |
Correct |
8 ms |
16784 KB |
Output is correct |
6 |
Correct |
9 ms |
16700 KB |
Output is correct |
7 |
Correct |
9 ms |
16796 KB |
Output is correct |
8 |
Correct |
12 ms |
16716 KB |
Output is correct |
9 |
Correct |
11 ms |
16788 KB |
Output is correct |
10 |
Correct |
9 ms |
16716 KB |
Output is correct |
11 |
Correct |
8 ms |
16764 KB |
Output is correct |
12 |
Correct |
8 ms |
16716 KB |
Output is correct |
13 |
Correct |
8 ms |
16740 KB |
Output is correct |
14 |
Correct |
9 ms |
16716 KB |
Output is correct |
15 |
Correct |
8 ms |
16716 KB |
Output is correct |
16 |
Correct |
9 ms |
16832 KB |
Output is correct |
17 |
Correct |
9 ms |
16776 KB |
Output is correct |
18 |
Correct |
9 ms |
16844 KB |
Output is correct |
19 |
Correct |
9 ms |
16840 KB |
Output is correct |
20 |
Correct |
9 ms |
16844 KB |
Output is correct |
21 |
Correct |
9 ms |
16736 KB |
Output is correct |
22 |
Correct |
9 ms |
16844 KB |
Output is correct |
23 |
Correct |
10 ms |
16972 KB |
Output is correct |
24 |
Correct |
10 ms |
17032 KB |
Output is correct |
25 |
Correct |
11 ms |
16972 KB |
Output is correct |
26 |
Correct |
11 ms |
17160 KB |
Output is correct |
27 |
Correct |
12 ms |
17140 KB |
Output is correct |
28 |
Correct |
21 ms |
19072 KB |
Output is correct |
29 |
Correct |
25 ms |
19448 KB |
Output is correct |
30 |
Correct |
46 ms |
22340 KB |
Output is correct |
31 |
Correct |
30 ms |
21236 KB |
Output is correct |
32 |
Correct |
34 ms |
21312 KB |
Output is correct |
33 |
Correct |
31 ms |
21128 KB |
Output is correct |
34 |
Correct |
33 ms |
21060 KB |
Output is correct |
35 |
Correct |
35 ms |
21572 KB |
Output is correct |
36 |
Correct |
36 ms |
21828 KB |
Output is correct |