Submission #502745

# Submission time Handle Problem Language Result Execution time Memory
502745 2022-01-06T14:26:16 Z amunduzbaev Triple Jump (JOI19_jumps) C++14
0 / 100
92 ms 27072 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	vector<int> a(n + 1);
	for(int i=1;i<=n;i++) cin>>a[i];
	
	vector<int> p(n);
	for(int i=0;i<n;i++) p[i] = i + 1;
	sort(p.begin(), p.end(), [&](int i, int j){
		return (a[i] > a[j]);
	});
	
	vector<vector<int>> mx(n + 1, vector<int>(20));
	for(int i=1;i<=n;i++) mx[i][0] = a[i];
	for(int j=1;j<20;j++){
		for(int i=1;i + (1 << (j - 1))<=n;i++){
			mx[i][j] = max(mx[i][j-1], mx[i + (1 << (j - 1))][j-1]);
		}
	}
	
	auto get = [&](int l, int r){
		if(l > r) return 0;
		int lg = __lg(r - l + 1);
		return max(mx[l][lg], mx[r - (1 << lg) + 1][lg]);
	};
	
	auto check = [&](int l, int r){
		int res = a[l] + a[r];
		res += max({get(l + 1, (r - l) / 2), get(max(1, l - (r - l)), l - 1), get(r + 1, min(n, r + (r - l)))});
		return res;
	};
	
	int B = min(n, 400);
	int res = 0;
	for(int i=0;i<B;i++){
		for(int j=i+1;j<B;j++){
			res = max(res, check(p[i], p[j]));
		}
	}
	
	cout<<res<<"\n";
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 92 ms 27072 KB Output is correct
2 Incorrect 72 ms 27068 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -