컨베이어 벨트
package ss;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class RobotOnConveyerBelt {
static int[] robot,conveyer;
static int N,K;
static void rotate_belt_robot() {
int tmp = conveyer[2*N-1];
int r_tmp = robot[2*N-1];
for(int i=2*N-1;i>0;i--) {
conveyer[i] = conveyer[i-1];
robot[i] = robot[i-1];
}
conveyer[0] = tmp;
robot[0] = r_tmp;
}
static int solve() {
int ans = 0;
int cnt = 0;
boolean flag = true;
while(flag) {
//1.로봇과 함께 벨트 회전.
rotate_belt_robot();
//2.로봇 이동.
int r_next = 0;//로봇현재위치 +1. 로봇 현재위치=?
if(robot[r_next]!=2 && conveyer[r_next] >=1) {//로봇이있는 경우.
robot[r_next] = 2;
conveyer[r_next]--;
}
//3.올리는 위치 0 아니면 로봇 올린다.
if(conveyer[0] != 0) {
robot[0] = 2;
conveyer[0]--;
} else {
rotate_belt_robot();
}
for(int i=0;i<2*N;i++) {
conveyer[i] = 0;
cnt++;
if(cnt == K) {
flag = false;
}
}
ans++;
}
return ans;
}
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
String[] input = br.readLine().split(" ");
N = Integer.parseInt(input[0]);
K = Integer.parseInt(input[1]);
robot = new int[2*N];
conveyer = new int[2*N];
for(int i=0;i<2*N;i++) {
conveyer[i] = sc.nextInt();
}
System.out.println(solve());
br.close();
}
}
// for(int i=0;i<2*N;i++) {//i=0,1,2,3,4,5
// input = br.readLine().split(" ");
// conveyer[i] = Integer.parseInt(input[i]);
// }
//for(int i=0;i<2*N;i++) {
// System.out.print(conveyer[i]+" ");
//}
//System.out.println();Last updated