Submission #991699

#TimeUsernameProblemLanguageResultExecution timeMemory
991699VMaksimoski008Divide and conquer (IZhO14_divide)C++17
100 / 100
72 ms4692 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; vector<array<int, 3> > v(n+1); for(int i=1; i<=n; i++) cin >> v[i][0] >> v[i][1] >> v[i][2]; ll P[n+1][3], ans = 0;; memset(P, 0, sizeof(P)); for(int i=1; i<=n; i++) for(int j=1; j<3; j++) P[i][j] = P[i-1][j] + v[i][j]; ll mn[n+1]; mn[0] = 1e18; for(int i=1; i<=n; i++) { mn[i] = min(mn[i-1], P[i-1][2] - v[i][0] + 1); int l=1, r=i, p=i; while(l <= r) { int mid = (l + r) / 2; if(mn[mid] <= P[i][2] - v[i][0]) p = mid, r = mid - 1; else l = mid + 1; } ans = max(ans, P[i][1] - P[p-1][1]); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...