๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm

[Codeforces] 1136A: Nastya is Reading a Book

by ์ฃผ๋ฐœ2 2020. 4. 6.
๋ฐ˜์‘ํ˜•

https://codeforces.com/problemset/problem/1136/A

 

Problem - 1136A - Codeforces

 

codeforces.com

์ฝ”๋“œ

import java.util.Scanner;

public class A1136 {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();		 // ์ฑ•ํ„ฐ ์ˆ˜ 
		int[][] arr = new int[n][2]; // ์ฑ•ํ„ฐ๋‹น ํŽ˜์ด์ง€ ๋ฒ”์œ„
		for(int i=0; i<n; i++) {
			arr[i][0] = scan.nextInt();
			arr[i][1] = scan.nextInt();
		}
		int k = scan.nextInt();		// ํ‘œ์‹œ๋œ ํŽ˜์ด์ง€

		for(int i=0; i<n; i++) {
			if(arr[i][1] >= k) {	// ์•ˆ์ฝ์€ ์ฑ•ํ„ฐ ์ฐพ๊ธฐ.
				System.out.println(n-i);
				return;
			}
		}


		scan.close();
	}

}

ํ’€์ด

์ฑ•ํ„ฐ๋‹น ํŽ˜์ด์ง€ ๋ฒ”์œ„๊ฐ€ ์ฃผ์–ด์ง€๊ณ , ํ˜„์žฌ ํ‘œ์‹œ๋œ ์ธ๋ฑ์Šค(k)๊ฐ€ ์ฃผ์–ด์งˆ๋•Œ, Nastya๊ฐ€ ๋ช‡๊ฐœ์˜ ์ฑ•ํ„ฐ๋ฅผ ์ฝ์–ด์•ผ ํ•˜๋Š”์ง€ ์ฐพ๋Š” ๋ฌธ์ œ.

์ฑ•ํ„ฐ์˜ ๋ ํŽ˜์ด์ง€(arr[i][1])๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ‘œ์‹œ๋œ ์ธ๋ฑ์Šค(k)์™€ ๋น„๊ตํ•ด๊ฐ€๋ฉฐ ์ปค์ง€๋Š” ๋ถ€๋ถ„์—์„œ n - i ๊ฐ’์„ ์ถœ๋ ฅํ•˜๋ฉด ์ •๋‹ต.

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€