This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 12;
void solve() {
int n;
cin >> n;
ll ans = 0;
pair<ll, pll> p[n];
for(int i = 0; i < n; i++) {
cin >> p[i].ff >> p[i].ss.ff >> p[i].ss.ss;
ans = max(ans, p[i].ss.ff);
}
sort(p, p + n);
set<pll> s;
s.insert({p[0].ff, 0});
ll t = p[0].ff;
for(int i = 1; i < n; i++) {
p[i].ss.ss += p[i - 1].ss.ss;
p[i].ss.ff += p[i - 1].ss.ff;
ll x = p[i].ff - p[i].ss.ss;
auto j = s.lower_bound({x, 0});
if(j != s.end()) {
ans = max(ans, p[i].ss.ff - (*j).ss);
}
if(t < p[i].ff - p[i - 1].ss.ss)s.insert({p[i].ff - p[i - 1].ss.ss, p[i - 1].ss.ff}), t = p[i].ff - p[i - 1].ss.ss;
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int tcs = 1;
//cin >> tcs;
for(int i = 1; i <= tcs; i++) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |