본문 바로가기

알고리즘 Algorithm

백준 1205

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int myScore = scan.nextInt();
		int P = scan.nextInt();
		int myRank = -1;
		int []ranking = new int[P];
		for(int i = 0; i < N; i++) {
			ranking[i] = scan.nextInt();
		}

		if (N == P && ranking[N - 1] >= myScore) myRank = -1;
		else {
			for (int i = 0; i < N; i++) {
				if (ranking[i] <= myScore) {
					myRank = i + 1;
					break;
				}
			}
			if (myRank == -1 && P > N) myRank = N;
		}

		System.out.println(myRank);
	}

}

 

'알고리즘 Algorithm' 카테고리의 다른 글

백준 1094, 1100  (0) 2020.12.30