# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
370887 | 2021-02-25T01:32:37 Z | R3KT | Hacker (BOI15_hac) | Java 11 | 0 ms | 0 KB |
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); } }