#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n;
int x[N],g[N],e[N];
set<pair<int,int> > s;
int ans;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
for(int i = 1;i <= n;i++) cin >> x[i] >> g[i] >> e[i],e[i]+=e[i-1],g[i]+=g[i-1];
for(int i = 1;i <= n;i++)
{
auto it = s.upper_bound({e[i]-x[i],INT_MAX});
if(it!=s.begin())
{
it--;
ans = max(ans,g[i]-it->second);
}
else ans = max(ans,g[i]-g[i-1]);
// add {e[i-1]-x[i],g[i-1]}
it = s.upper_bound({e[i-1]-x[i],INT_MAX});
bool out = false;
if(it!=s.begin())
{
it--;
if(it->second<g[i-1]) out = true;
}
if(out) continue;
it = s.lower_bound({e[i-1]-x[i],INT_MAX});
while(it!=s.end() and it->second>=g[i-1]) it = s.erase(it);
s.insert({e[i-1]-x[i],g[i-1]});
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |