#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int NMAX = 5e5;
const int INF = 2e9;
int n, k;
int s, answer;
int a[2 * NMAX + 1];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
a[n + i] = a[i];
}
k = n / 2 + n % 2;
answer = INF;
for(int i = n + 1 - k + 1; i - k + 1 <= n + 1; i++) {
s += a[i];
if(i >= n + 1) {
answer = min(answer, s);
s -= a[i - k + 1];
}
}
cout << answer << '\n';
return 0;
}
/*
1 2 3 4 5 1 2 3 4 5
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |