제출 #31683

#제출 시각아이디문제언어결과실행 시간메모리
31683aomeHacker (BOI15_hac)C++14
100 / 100
349 ms25612 KiB
/*input 5 1 1 1 1 1 */ #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> using namespace std; #define sp ' ' #define endl '\n' #define fi first #define se second #define mp make_pair #define int long long #define N 500005 int n; int a[N]; int sum[N]; int f[4 * N]; int getsum(int l, int r) { return sum[r] - sum[l - 1]; } int ceil(int x, int y) { int ret = x / y; if (x % y) ret++; return ret; } void update(int k, int l, int r, int pos, int val) { if (pos < l || r < pos) return; if (l == r) { f[k] = val; return; } int mid = (l + r) / 2; update(k * 2, l, mid, pos, val); update(k * 2 + 1, mid + 1, r, pos, val); f[k] = max(f[k * 2], f[k * 2 + 1]); } int get(int k, int l, int r, int L, int R) { if (r < L || R < l) return 0; if (L <= l && r <= R) return f[k]; int mid = (l + r) / 2; return max(get(k * 2, l, mid, L, R), get(k * 2 + 1, mid + 1, r, L, R)); } // https://oj.uz/problem/view/BOI15_hac signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i]; int ans = 0; for (int i = 1; i <= n; i++) { int last = i + n / 2 - 1; if (last <= n) { update(1, 1, n, i, getsum(i, last)); } else { update(1, 1, n, i, getsum(i, n) + getsum(1, n / 2 - (n - i + 1))); } } for (int i = 1; i <= n; i++) { int last = i - n / 2; if (last < 0) last += n; int res = 0; if (last < i) { if (i != n) res = get(1, 1, n, i + 1, n); res = max(res, get(1, 1, n, 1, last)); } else { res = get(1, 1, n, i + 1, last); } ans = max(ans, sum[n] - res); } cout << ans << 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...