#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "tests"
#define pll pair<ll, ll>
#define pi pair<ll, pll>
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll N = 2e5+5;
const int base = 313;
ll n, m, t, k, T, ans, q, tong, c[N], a[N], b[N], h[N], P[N][20];
vector<ll> adj[N], kq;
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
ll sum(ll l, ll r)
{
if(l <= r)return b[r] - b[l-1];
return b[r] + b[n] - b[l-1];
}
ll mx(ll l, ll r)
{
ll log = log2(r-l+1);
return max(P[l][log], P[r-(1<<log)+1][log]);
}
ll get(ll l, ll r)
{
if(l <= r)return mx(l, r);
return max(mx(1, r), mx(l, n));
}
void sol()
{
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
b[i] = b[i-1] + a[i];
}
for(int i = 1; i <= n; i ++)
{
int j = i + n/2 - 1;
if(j > n)j -= n;
P[i][0] = sum(i, j);
}
for(int j = 1; j < 19; j ++)
{
for(int i = 1; i+(1<<j)-1 <= n; i ++)P[i][j] = max(P[i][j-1], P[i+(1<<(j-1))][j-1]);
}
for(int i = 1; i <= n; i ++)
{
int l = i + 1, r = i - n / 2;
if(l > n)l -= n;
if(r <= 0)r += n;
ans = max(ans, b[n]- get(l, r));
}
cout << ans;
}
int main()
{
if(fopen(task".in", "r"))
{
freopen(task".in", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
Compilation message
hac.cpp: In function 'int main()':
hac.cpp:72:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | freopen(task".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
hac.cpp:73:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
5020 KB |
Output is correct |
7 |
Correct |
4 ms |
5016 KB |
Output is correct |
8 |
Correct |
3 ms |
5068 KB |
Output is correct |
9 |
Correct |
3 ms |
5020 KB |
Output is correct |
10 |
Correct |
3 ms |
5016 KB |
Output is correct |
11 |
Correct |
4 ms |
5068 KB |
Output is correct |
12 |
Correct |
3 ms |
5068 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
5024 KB |
Output is correct |
17 |
Correct |
3 ms |
5068 KB |
Output is correct |
18 |
Correct |
3 ms |
5068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
5020 KB |
Output is correct |
7 |
Correct |
4 ms |
5016 KB |
Output is correct |
8 |
Correct |
3 ms |
5068 KB |
Output is correct |
9 |
Correct |
3 ms |
5020 KB |
Output is correct |
10 |
Correct |
3 ms |
5016 KB |
Output is correct |
11 |
Correct |
4 ms |
5068 KB |
Output is correct |
12 |
Correct |
3 ms |
5068 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
5024 KB |
Output is correct |
17 |
Correct |
3 ms |
5068 KB |
Output is correct |
18 |
Correct |
3 ms |
5068 KB |
Output is correct |
19 |
Correct |
3 ms |
5068 KB |
Output is correct |
20 |
Correct |
3 ms |
5148 KB |
Output is correct |
21 |
Correct |
3 ms |
5148 KB |
Output is correct |
22 |
Correct |
4 ms |
5580 KB |
Output is correct |
23 |
Correct |
5 ms |
5836 KB |
Output is correct |
24 |
Correct |
5 ms |
5452 KB |
Output is correct |
25 |
Correct |
5 ms |
5836 KB |
Output is correct |
26 |
Correct |
5 ms |
5836 KB |
Output is correct |
27 |
Correct |
4 ms |
5024 KB |
Output is correct |
28 |
Correct |
3 ms |
4940 KB |
Output is correct |
29 |
Correct |
3 ms |
4940 KB |
Output is correct |
30 |
Correct |
5 ms |
5796 KB |
Output is correct |
31 |
Correct |
5 ms |
5804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5016 KB |
Output is correct |
2 |
Correct |
4 ms |
5068 KB |
Output is correct |
3 |
Correct |
4 ms |
5836 KB |
Output is correct |
4 |
Correct |
36 ms |
19120 KB |
Output is correct |
5 |
Correct |
95 ms |
40200 KB |
Output is correct |
6 |
Runtime error |
90 ms |
87092 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
5020 KB |
Output is correct |
7 |
Correct |
4 ms |
5016 KB |
Output is correct |
8 |
Correct |
3 ms |
5068 KB |
Output is correct |
9 |
Correct |
3 ms |
5020 KB |
Output is correct |
10 |
Correct |
3 ms |
5016 KB |
Output is correct |
11 |
Correct |
4 ms |
5068 KB |
Output is correct |
12 |
Correct |
3 ms |
5068 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
5024 KB |
Output is correct |
17 |
Correct |
3 ms |
5068 KB |
Output is correct |
18 |
Correct |
3 ms |
5068 KB |
Output is correct |
19 |
Correct |
3 ms |
5068 KB |
Output is correct |
20 |
Correct |
3 ms |
5148 KB |
Output is correct |
21 |
Correct |
3 ms |
5148 KB |
Output is correct |
22 |
Correct |
4 ms |
5580 KB |
Output is correct |
23 |
Correct |
5 ms |
5836 KB |
Output is correct |
24 |
Correct |
5 ms |
5452 KB |
Output is correct |
25 |
Correct |
5 ms |
5836 KB |
Output is correct |
26 |
Correct |
5 ms |
5836 KB |
Output is correct |
27 |
Correct |
4 ms |
5024 KB |
Output is correct |
28 |
Correct |
3 ms |
4940 KB |
Output is correct |
29 |
Correct |
3 ms |
4940 KB |
Output is correct |
30 |
Correct |
5 ms |
5796 KB |
Output is correct |
31 |
Correct |
5 ms |
5804 KB |
Output is correct |
32 |
Correct |
4 ms |
5016 KB |
Output is correct |
33 |
Correct |
4 ms |
5068 KB |
Output is correct |
34 |
Correct |
4 ms |
5836 KB |
Output is correct |
35 |
Correct |
36 ms |
19120 KB |
Output is correct |
36 |
Correct |
95 ms |
40200 KB |
Output is correct |
37 |
Runtime error |
90 ms |
87092 KB |
Execution killed with signal 11 |
38 |
Halted |
0 ms |
0 KB |
- |