Submission #1128012

#TimeUsernameProblemLanguageResultExecution timeMemory
1128012Halym2007Hacker (BOI15_hac)C++17
100 / 100
227 ms28456 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define sz size() #define ff first #define ss second #define pb push_back #define pii pair <int, int> #define dur exit(0) #define dur1 return(0) const int NN = 1e6 + 5; ll n, p[NN], a[NN], sum, st[NN * 4]; void update (int idx, int x, int y, int l, ll r) { if (x == y) { st[idx] = r; return; } int mid = (x + y) / 2; if (l <= mid) update (idx * 2, x, mid, l, r); else update (idx * 2 + 1, mid + 1, y, l, r); st[idx] = max (st[idx * 2], st[idx * 2 + 1]); } void jogap (int idx, int x, int y, int l, int r) { if (l <= x and y <= r) { sum = max (st[idx], sum); return; } if (l > y or x > r) return; int mid = (x + y) / 2; jogap (idx * 2, x, mid, l, r); jogap (idx * 2 + 1, mid + 1, y, l, r); } int main () { // freopen ("input.txt", "r", stdin); ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; a[i + n] = a[i]; } for (int i = 1; i <= 2 * n; ++i) { p[i] = p[i - 1] + a[i]; } int ope = n / 2; for (int i = 1; i <= 2 * n; ++i) { if (i + ope - 1 > 2 * n) break; update (1, 1, 2 * n, i, p[i + ope - 1] - p[i - 1]); } ll mx = 0, jog = 0; for (int i = 1; i <= n; ++i) { ll jog = 0; sum = 0; jogap (1, 1, 2 * n, i + 1, (n + i - 1) - ope + 1); jog = max (jog, sum); mx = max (mx, p[n] - jog); if (mx == 14) { cout << i << " " << sum; return 0; } } cout << mx; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...