Submission #137483

#TimeUsernameProblemLanguageResultExecution timeMemory
137483silxikysHacker (BOI15_hac)C++14
60 / 100
60 ms10360 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 5e5+5; int n; int v[2*maxn]; int pre[2*maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { cin >> v[i]; v[i+n] = v[i]; } pre[0] = v[0]; for (int i = 1; i < 2*n; i++) { pre[i] = pre[i-1] + v[i]; } int total = pre[n-1]; if (n <= 5000) { int res = 0; for (int i = 0; i < n; i++) { int maxSum = 0; for (int j = i+n/2; j < i+n; j++) { maxSum = max(maxSum,pre[j]-pre[j-n/2]); } res = max(res,total-maxSum); } cout << res << '\n'; } else { int res = 0; for (int i = 0; i < 1; i++) { int maxSum = 0; for (int j = i+n/2; j < i+n; j++) { maxSum = max(maxSum,pre[j]-pre[j-n/2]); } res = max(res,total-maxSum); } cout << res << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...