Study/알고리즘 문제풀이
백준 3985. 롤 케이크 :: 돼지개발자
돼지개발자
2018. 11. 15. 11:03
출저 : https://www.acmicpc.net/problem/3985
"시뮬레이션"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; class Main { static int L,N; static int[] map; static int[][] dist; static int max1,max2,idx1,idx2; public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); L = Integer.parseInt(br.readLine()); N = Integer.parseInt(br.readLine()); map = new int[L+1]; dist = new int[N+1][2]; for (int i = 1; i <= N; i++) { StringTokenizer st = new StringTokenizer(br.readLine()); dist[i][0] = Integer.parseInt(st.nextToken()); dist[i][1] = Integer.parseInt(st.nextToken()); int gap = dist[i][1] - dist[i][0]; int cnt = 0; for (int a = dist[i][0]; a <= dist[i][1] ; a++) { if(map[a] == 0){ map[a] = i; cnt++; } } if(gap > max1) { max1 = gap; idx1 = i; } if( cnt > max2) { max2 = cnt; idx2 = i; } } System.out.println(idx1+"\n"+idx2); } } | cs |