# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
370887 | R3KT | Hacker (BOI15_hac) | Java | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.util.*;
import java.io.*;
public class Hacker {
// https://oj.uz/problem/view/BOI15_hac
public static void main(String[] args) throws IOException, FileNotFoundException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader in = new BufferedReader(new FileReader("Hacker"));
int n = Integer.parseInt(in.readLine());
long[] arr = new long[n];
StringTokenizer st = new StringTokenizer(in.readLine());
for (int i=0; i<n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
ArrayList<Long> sums = new ArrayList<Long>();
long sum=0;
int k = (n+1)/2;
for (int i=0; i<k; i++) {
sum += arr[i];
}
sums.add(sum);
for (int i=0; i<n-1; i++) {
sum -= arr[i];
sum += (arr[(i+k)%n]);
sums.add(sum);
}
long ans=Math.min(sums.get(sums.size()-1), sums.get(0));
for (int i=0; i<sums.size()-1; i++) {
ans = Math.max(ans, Math.min(sums.get(i), sums.get(i+1)));
}
System.out.println(ans);
}
}