[백준] 1756 피자굽기?

`

들어갈 수 있는 값을 구하고 뒤에서부터 비교함


 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	static int N,M,next = Integer.MAX_VALUE;
	static int arr[];
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		N = Integer.parseInt(st.nextToken());
		M = Integer.parseInt(st.nextToken());
		arr = new int[N+1];
		st = new StringTokenizer(br.readLine());
		
		for (int i = 1; i <= N; i++) {
			arr[i] = Integer.parseInt(st.nextToken());
			arr[i] = Math.min(next, arr[i]);
			next = arr[i];
		}
		int left=0,right = N;
		st = new StringTokenizer(br.readLine());
		
		for (int i = 0; i < M; i++) {
			int now = Integer.parseInt(st.nextToken());
			
			while(right>0 && arr[right]<now) {
				right--;
			}
			right--;
			if(right<0) break;
			
		}
		System.out.println(right<0?0:right+1);
	}

}
updatedupdated2021-05-032021-05-03
Load Comments?