Submission #770448

#TimeUsernameProblemLanguageResultExecution timeMemory
770448BlagojDivide and conquer (IZhO14_divide)C++17
17 / 100
1 ms332 KiB
#include <bits/stdc++.h> #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif #pragma GCC optimize("Ofast,unroll-loops") using namespace std; #define endl '\n' #define ll long long #define all(x) x.begin(), x.end() struct T { ll pos, gold, cost; }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; T a[n]; ll ans = 0; for (int i = 0; i < n; i++) { cin >> a[i].pos >> a[i].gold >> a[i].cost; ans = max(ans, a[i].gold); } ll l = 0, sumCost = a[0].cost, sumGold = a[0].gold; for (int r = 1; r < n; r++) { sumCost += a[r].cost; sumGold += a[r].gold; while (sumCost < a[r].pos - a[l].pos) { sumCost -= a[l].cost; sumGold -= a[l].gold; l++; } ans = max(ans, sumGold); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...