이런 형태의 문제에 특히 약해 쉬운거부터 다시 해본다.
가로, 세로를 입력할 때 거꾸로 했는데, 가로로 자른다는게 y좌표를 의미하고, 세로로 자른다는게 x좌표를 의미하기 때문이다.
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class bj2628 {
static Scanner sc = new Scanner(System.in);
static int x, y;
static ArrayList<Integer> xCutting = new ArrayList<Integer>();
static ArrayList<Integer> yCutting = new ArrayList<Integer>();
public static void main(String[] args) {
inputData();
System.out.println(findAnswer());
sc.close();
}
public static void inputData() {
int n, i, direction, point;
x = sc.nextInt();
y = sc.nextInt();
xCutting.add(x);
yCutting.add(y);
xCutting.add(0);
yCutting.add(0);
n = sc.nextInt();
for(i = 0; i < n; i++) {
direction = sc.nextInt();
point = sc.nextInt();
if(direction == 1) {
xCutting.add(point);
}
else{
yCutting.add(point);
}
}
}
public static int findAnswer() {
int answer = 0, i;
int maxX = 0, maxY = 0;
Collections.sort(xCutting);
Collections.sort(yCutting);
System.out.print("xCutting : ");
for(int temp : xCutting) {
System.out.print(temp + " ");
}
System.out.print("\nyCutting : ");
for(int temp : yCutting) {
System.out.print(temp + " ");
}
System.out.println();
for(i = 1; i < xCutting.size(); i++) {
maxX = Math.max(maxX, xCutting.get(i) - xCutting.get(i - 1));
}
for(i = 1; i < yCutting.size(); i++) {
maxY = Math.max(maxY, yCutting.get(i) - yCutting.get(i - 1));
}
System.out.println("maxX : " + maxX + ", maxY : " + maxY);
answer = maxX * maxY;
return answer;
}
}