#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define PB push_back
#define MP make_pair
#define ft first
#define sd second
#define pll pair<ll, ll>
using namespace std;
typedef long long ll;
const ll OO = 1e18;
const int N = 100100;
vector<pll> vc;
vector<ll> suf;
ll ans = 0;
int n, x[N], g[N], e[N];
void calc(int l, int r){
if (l == r){
ans = max(ans, (ll)g[l]);
return;
}
int md = (l + r) >> 1;
calc(l, md);
calc(md + 1, r);
vc.clear();
ll sm = 0, en = 0;
for (int i = md; i >= l; i--) {
sm += g[i];
en += e[i];
vc.PB(MP(en + x[i], sm));
}
sort(all(vc));
suf.resize(sz(vc) + 1);
suf[sz(vc)] = -OO;
for (int i = sz(vc) - 1; i >= 0; i--)
suf[i] = max(suf[i + 1], vc[i].sd);
sm = en = 0;
for (int i = md + 1; i <= r; i++){
sm += g[i];
en += e[i];
int ps = lower_bound(all(vc), MP(-(en - ll(x[i])), -OO)) - vc.begin();
ans = max(ans, suf[ps] + sm);
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("penguins.in","r",stdin); freopen("penguins.out","w",stdout);
// freopen("in.txt","r",stdin);
cin >> n;
for (int i = 0; i < n; i++)
cin >> x[i] >> g[i] >> e[i];
calc(0, n - 1);
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
12 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
396 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
508 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
5 ms |
632 KB |
Output is correct |
12 |
Correct |
5 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
632 KB |
Output is correct |
2 |
Correct |
10 ms |
760 KB |
Output is correct |
3 |
Correct |
8 ms |
888 KB |
Output is correct |
4 |
Correct |
36 ms |
2752 KB |
Output is correct |
5 |
Correct |
39 ms |
3036 KB |
Output is correct |
6 |
Correct |
83 ms |
5972 KB |
Output is correct |
7 |
Correct |
71 ms |
4916 KB |
Output is correct |
8 |
Correct |
71 ms |
4948 KB |
Output is correct |
9 |
Correct |
73 ms |
4816 KB |
Output is correct |
10 |
Correct |
75 ms |
4692 KB |
Output is correct |
11 |
Correct |
70 ms |
5252 KB |
Output is correct |
12 |
Correct |
73 ms |
5460 KB |
Output is correct |