Submission #680928

#TimeUsernameProblemLanguageResultExecution timeMemory
680928oblantisDivide and conquer (IZhO14_divide)C++17
100 / 100
56 ms10968 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...