제출 코드
- 사용 알고리즘 :
구현
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
package bronze;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class B3985_rollCake {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int L = Integer.parseInt(br.readLine());
int N = Integer.parseInt(br.readLine());
int[] cake = new int[L+1];
int max = Integer.MIN_VALUE;
int pre_person = -1;
for(int n=1; n<=N; n++) {
String[] line = br.readLine().split(" ");
int start =Integer.parseInt(line[0]);
int end =Integer.parseInt(line[1]);
if(max < end-start) {
pre_person = n;
max = end-start;
}
for(int i=start; i<=end; i++) {
if(cake[i]==0) cake[i] = n;
}
}
int[] count = new int[N+1];
int real_person = -1;
max = Integer.MIN_VALUE;
for(int i=1; i<=L; i++) {
if(cake[i] == 0) continue;
count[cake[i]]++;
if(max < count[cake[i]]) {
real_person = cake[i];
max = count[real_person];
}
}
System.out.println(pre_person + "\n" + real_person );
}
}