풀이 방법
짝수, 홀수 번호인 카드를 나눠서 저장했다.
나에게 줄 차례에 밑장빼기 하는 경우와 상대방에게 줄 차례에 밑장 빼기 하는 경우 이 두가지를 생각해서 풀이 하면 된다.
내 코드
package com.company;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
int[] a = new int[N / 2 + 1];
int[] b = new int[N / 2 + 1];
for (int i = 1; i <= N / 2; i++) {
a[i] = a[i - 1] + Integer.parseInt(st.nextToken());
b[i] = b[i - 1] + Integer.parseInt(st.nextToken());
}
for (int i = 1; i <= N / 2; i++) {
System.out.println(a[i] + " " + b[i]);
}
int max = Math.max(a[N / 2], b[N / 2]);
for (int i = 1; i <= N / 2; i++) {
int x = a[i - 1] + b[N / 2] - b[i - 1];
int y = a[i] + b[N / 2 - 1] - b[i - 1];
max = Math.max(Math.max(x, max), y);
}
System.out.println(max);
}
}
'코딩테스트 > [백준] 코딩테스트 연습' 카테고리의 다른 글
2048 (Easy) - 12100번 (0) | 2022.03.07 |
---|---|
연구소 - 14502번 (0) | 2022.03.04 |
강의실 배정 - 11000번 (0) | 2022.02.28 |
찾기 - 1786번 (0) | 2022.02.24 |
치킨 배달 - 15686번 (0) | 2022.02.23 |