풀이)
x ,y좌표 둘 중 작은 값을 선택해서 먼저 간다( 큰 값을 고를 경우 원하는 좌표 그 이상을 가버릴 수도 있다)
그리고 나머지는 x-y 절댓값을 통해 대각선으로 얼마만큼 이동하고 원하는 좌표까지 얼마나 남았는지 알 수 있다.
이 절댓값을 더해주면 된다. 4가지 경우로 나누어 그 중 가장 작은 값을 출력하면 풀 수 있다.
내 코드)
package com.example.algorithgm.today;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Work {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
long x=Long.parseLong(st.nextToken());
long y=Long.parseLong(st.nextToken());
long w=Long.parseLong(st.nextToken()); //평행이동시간
long s=Long.parseLong(st.nextToken()); //대각선이동시간
long temp1,temp2,temp3;
//1. 평행이동만 할떄
temp1 = (x+y) * w;
temp2 = 0;
//
if((x+y) % 2 == 0){
temp2 = Math.max(x,y) * s;
}else{
temp2 = (Math.max(x,y) - 1) * s + w;
}
temp3 = (Math.min(x, y))*s+(Math.abs(x-y))*w;
System.out.println(Math.min(temp1, Math.min(temp2, temp3)));
}
}