Submission #848167

# Submission time Handle Problem Language Result Execution time Memory
848167 2023-09-11T13:24:10 Z Hakiers Hacker (BOI15_hac) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 7;
int sumpref[MAXN];
int n;

int sum(int a, int b){
	return sumpref[b] - sumpref[a-1];
}

int solve(){
	
	int res = 0;
	int bestabs = 2e9;
	
	int k = n/2;
	for(int i = 1; i + k <= n; i++){
		if(abs(sum(i, k+i-1) - (sumpref[n] - sum(i, k+i-1))) < bestabs){
			res = max(sum(i, k+i-1), sumpref[n] - sum(i, k+i-1));
			bestabs = abs(sum(i, k+i-1) - (sumpref[n] - sum(i, k+i-1)));
		}
		else if(abs(sum(i, k+i-1) - (sumpref[n] - sum(i, k+i-1))) <= bestabs)
			res = max(max(res, sum(i, k+i-1)), sumpref[n] - sum(i, k+i-1));
	}

	
	return res;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> sumpref[i];
		sumpref[i] += sumpref[i-1];
	}
	
	cout << solve() << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -