# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
198309 | 2020-01-25T14:41:12 Z | dndhk | Hacker (BOI15_hac) | C++14 | 3 ms | 504 KB |
#include <bits/stdc++.h> #define pb push_back using namespace std; const int MAX_N = 500000; typedef pair<int, int> pii; int N; int arr[MAX_N+1], sum[MAX_N+1]; int c[MAX_N+1]; vector<pii> vt; int main(){ scanf("%d", &N); for(int i=1; i<=N; i++){ scanf("%d", &arr[i]); sum[i] = sum[i-1] + arr[i]; } for(int i=1; i<=N; i++){ if(i+(N/2)-1<=N){ c[i] = sum[i+(N/2)-1] - sum[i-1]; }else{ c[i] = sum[N] - sum[i-1] + sum[(i+(N/2)-1)%N]; } vt.pb({c[i], i}); } sort(vt.begin(), vt.end()); int s = vt.back().second, e = (s+(N/2)-2)%N+1; vt.pop_back(); while(!vt.empty()){ int ns = vt.back().second, ne = (ns+(N/2)-2)%N+1; if(ns<=ne){ if(s<=e){ s = max(s, ns); e = min(e, ne); }else{ if(ns>=s){ s = max(ns, s); e = ne; }else{ e = min(e, ne); s = ns; } } }else{ if(s<=e){ if(ns<=s){ s = max(ns, s); }else{ e = min(e, ne); } }else{ s = max(ns, s); e = min(ne, e); } } if(s>e) break; vt.pop_back(); } printf("%d\n", sum[N] - vt.back().first); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Incorrect | 3 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Incorrect | 3 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Incorrect | 3 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Incorrect | 3 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |