Submission #1040392

#TimeUsernameProblemLanguageResultExecution timeMemory
1040392vjudge1Divide and conquer (IZhO14_divide)C++17
100 / 100
63 ms7932 KiB
#include <bits/stdc++.h> using namespace std; main() { long long n; cin >> n; vector<long long> x(n+1), g(n+1), d(n+1), g1(n+1, 0), d1(n+1, 0); for (long long i = 1; i <= n; ++i) { cin >> x[i] >> g[i] >> d[i]; g1[i] = g1[i-1] + g[i]; d1[i] = d1[i-1] + d[i]; } vector <long long> h(n+2); for (long long i=1; i<=n+1; i++) h[i]=-1e15; for (long long i=n; i>=1; i--) h[i]=max(h[i+1],d1[i]-x[i]); long long res = 0; for (long long i=1; i<=n; i++) { long long l = i, r = n, temp; while(l <= r) { long long mid = (l + r) / 2; if (h[mid] >= d1[i - 1] - x[i]) { temp = mid; l = mid + 1; } else r = mid - 1; } res=max(res,g1[temp] - g1[i - 1]); } cout << res; return 0; }

Compilation message (stderr)

divide.cpp:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | main()
      | ^~~~
divide.cpp: In function 'int main()':
divide.cpp:36:28: warning: 'temp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   36 |         res=max(res,g1[temp] - g1[i - 1]);
      |                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...