일상

3985 : 롤 케이크

STUDYING,,, 2021. 8. 16. 21:36
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in); // 스캐너 입력 선언
		int size = sc.nextInt(); // 롤 케이크 사이즈
		int max1 = Integer.MIN_VALUE; // 맥스값을 두개를 구해야하기 때문에 2개 선언
		int max2 = Integer.MIN_VALUE;
		int man1 = 0, man2 = 0; //몇번 째 사람인지 저장하는 변수
		int N = sc.nextInt(); // 총 사람 수
		
		int[] arr = new int[size];
		LinkedList<Integer> cntArr = new LinkedList<>(); // 실제로 받을 갯수 저장
		LinkedList<Integer> dif = new LinkedList<>(); // 예상으로 받을 갯수 저장

		
		for (int i = 0; i < N; i++) {
			int start = sc.nextInt();
			int end = sc.nextInt();
			int cnt = 0;
			for (int j = start; j < size; j++) {
				
				if (arr[j] == 0) {
					cnt++; // 0일 경우 카운트 +1하고 1값으로 바꿔주어 롤케이크가 없다고 표시
					arr[j] = 1;
				}
				if(j==end) break;

			}
			cntArr.add(cnt); // 실제로 받은 갯수를 cntArr저장
			dif.add(end - start); // 예상받을 갯수를 dif에 저장
		}
		for (int i = 0; i < N; i++) { // 각 cntArr과 dif에서의 최대값 구하는 반복문
			if (max1 < dif.get(i)) {
				max1 = dif.get(i);

			}
			if (max2 < cntArr.get(i)) {
				max2 = cntArr.get(i);
			}
		}

		for (int i = N-1; i >= 0; i--) { // 각 cntArr과 dif에서의 최대값이 몇번 째 사람인지 구하는 반복문
			if (max1 == dif.get(i))
				man1 = i;
			if (max2 == cntArr.get(i))
				man2 = i;
		}
		System.out.println(man1+1);
		System.out.println(man2+1);
	}
}

'일상' 카테고리의 다른 글

2309 : 일곱 난쟁이  (0) 2021.08.17
11399 : ATM  (0) 2021.08.16
16926 : 배열 돌리기 1  (0) 2021.08.14
2961 : 도영이가 만든 맛있는 음식  (0) 2021.08.14
2798 : 블랙잭  (0) 2021.08.13