#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define ll long long
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
#define deb(x) cerr<<#x << " : " << x << "\n";
using namespace std ;
const ll maxn = 4e5 + 10 , mod = 1e9 + 7 , inf =1e14 ;
int a[maxn];
vector<ll> comb(vector<ll> a, vector<ll> b){
vector <ll>res(sz(a) + sz(b)-1);
int id0 = 0 , id1 =0 ;
while(!(id0 == sz(a)-1 && id1 == sz(b)-1)){
res[id0+id1] = a[id0] + b[id1] ;
if(id0!=sz(a)-1 && (id1==sz(b)-1 || a[id0+1]-a[id0] > b[id1+1]-b[id1])){
id0++;
}else{
id1++;
}
}
res[sz(a)+sz(b)-2] = a.back() + b.back() ;
return res;
}
vector<vector<vector<ll>>> slv(int l, int r){
if(l + 1 == r){
return {{{0, -inf}, {-inf, -inf}}, {{-inf, -inf}, {-inf, a[l]}}};
}
int mid = (l + r)>>1;
auto resl = slv(l, mid), resr = slv(mid, r);
int len = (r - l + 1)/2 + 1;
vector<vector<vector<ll>>> res(2, vector<vector<ll>>(2));
rep(i,0,1){
rep(j,0,1){
res[i][j] = comb(resl[i][0], resr[0][j]);
rep(t,0,1){
vector<ll> tmp = comb(resl[i][t], resr[t^1][j]);
rep(k,0,sz(tmp)-1) res[i][j][k] = max(res[i][j][k], tmp[k]);
}
res[i][j].resize(len);
}
}
return res;
}
int main(){
ios::sync_with_stdio(0) ;cin.tie(0);
int n; cin >> n;
rep(i,0,n-1) cin >> a[i];
auto res = slv(0, n);
vector<ll> ans = res[0][0];
rep(i,0,1) rep(j,0,1){
rep(k,0,sz(ans)-1) ans[k] = max(ans[k], res[i][j][k]);
}
rep(i,1,((n+1)>>1)){
cout << ans[i] << '\n';
}
return 0-0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
604 KB |
Output is correct |
3 |
Correct |
3 ms |
372 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
4 ms |
604 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
4 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
604 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
4 ms |
604 KB |
Output is correct |
12 |
Correct |
4 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
516 KB |
Output is correct |
14 |
Correct |
4 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
604 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
4 ms |
476 KB |
Output is correct |
18 |
Correct |
3 ms |
616 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
604 KB |
Output is correct |
3 |
Correct |
3 ms |
372 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
4 ms |
604 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
4 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
604 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
4 ms |
604 KB |
Output is correct |
12 |
Correct |
4 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
516 KB |
Output is correct |
14 |
Correct |
4 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
604 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
4 ms |
476 KB |
Output is correct |
18 |
Correct |
3 ms |
616 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
3 ms |
604 KB |
Output is correct |
21 |
Correct |
349 ms |
13580 KB |
Output is correct |
22 |
Correct |
360 ms |
13532 KB |
Output is correct |
23 |
Correct |
352 ms |
13536 KB |
Output is correct |
24 |
Correct |
326 ms |
13440 KB |
Output is correct |
25 |
Correct |
310 ms |
13412 KB |
Output is correct |
26 |
Correct |
313 ms |
13280 KB |
Output is correct |
27 |
Correct |
318 ms |
13464 KB |
Output is correct |
28 |
Correct |
319 ms |
13536 KB |
Output is correct |
29 |
Correct |
320 ms |
13532 KB |
Output is correct |
30 |
Correct |
324 ms |
13536 KB |
Output is correct |
31 |
Correct |
320 ms |
13556 KB |
Output is correct |
32 |
Correct |
320 ms |
13560 KB |
Output is correct |
33 |
Correct |
328 ms |
13280 KB |
Output is correct |
34 |
Correct |
334 ms |
13436 KB |
Output is correct |
35 |
Correct |
337 ms |
13280 KB |
Output is correct |
36 |
Correct |
349 ms |
13528 KB |
Output is correct |
37 |
Correct |
367 ms |
13600 KB |
Output is correct |
38 |
Correct |
352 ms |
13528 KB |
Output is correct |
39 |
Correct |
321 ms |
13300 KB |
Output is correct |
40 |
Correct |
312 ms |
13348 KB |
Output is correct |
41 |
Correct |
318 ms |
13512 KB |
Output is correct |
42 |
Correct |
343 ms |
13600 KB |
Output is correct |
43 |
Correct |
357 ms |
13752 KB |
Output is correct |
44 |
Correct |
321 ms |
13696 KB |
Output is correct |
45 |
Correct |
322 ms |
13760 KB |
Output is correct |
46 |
Correct |
320 ms |
13600 KB |
Output is correct |
47 |
Correct |
328 ms |
13716 KB |
Output is correct |
48 |
Correct |
339 ms |
13384 KB |
Output is correct |
49 |
Correct |
332 ms |
13328 KB |
Output is correct |
50 |
Correct |
332 ms |
13564 KB |
Output is correct |