Submission #848167

#TimeUsernameProblemLanguageResultExecution timeMemory
848167HakiersHacker (BOI15_hac)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 7; int sumpref[MAXN]; int n; int sum(int a, int b){ return sumpref[b] - sumpref[a-1]; } int solve(){ int res = 0; int bestabs = 2e9; int k = n/2; for(int i = 1; i + k <= n; i++){ if(abs(sum(i, k+i-1) - (sumpref[n] - sum(i, k+i-1))) < bestabs){ res = max(sum(i, k+i-1), sumpref[n] - sum(i, k+i-1)); bestabs = abs(sum(i, k+i-1) - (sumpref[n] - sum(i, k+i-1))); } else if(abs(sum(i, k+i-1) - (sumpref[n] - sum(i, k+i-1))) <= bestabs) res = max(max(res, sum(i, k+i-1)), sumpref[n] - sum(i, k+i-1)); } return res; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> sumpref[i]; sumpref[i] += sumpref[i-1]; } cout << solve() << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...