Submission #338028

#TimeUsernameProblemLanguageResultExecution timeMemory
338028BeanZDivide and conquer (IZhO14_divide)C++14
100 / 100
36 ms3436 KiB
// I_Love_LPL #include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 1e5 + 50; long long mod = 1e9 + 7; const int lim = 700; const int lg = 18; const int base = 311; const long double eps = 1e-6; ll sume[N], sumg[N], mn[N]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("tests.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll n; cin >> n; mn[0] = 1e18; ll ans = 0; for (int i = 1; i <= n; i++){ ll x, g, d; cin >> x >> g >> d; ll l = 1, h = i - 1; sume[i] = sume[i - 1] + d; sumg[i] = sumg[i - 1] + g; ll cost = sume[i] - x; while (l <= h){ ll mid = (l + h) >> 1; if (mn[mid] > cost){ l = mid + 1; } else { h = mid - 1; } } ans = max(ans, sumg[i] - sumg[l - 1]); mn[i] = min(mn[i - 1], sume[i - 1] - x); //cout << mn[i] << " " << cost << endl; } cout << ans; } /* Ans: Out: */

Compilation message (stderr)

divide.cpp: In function 'int main()':
divide.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   17 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   18 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...