-- 기타 --/Problem Solve

[Codeforces Round 939] A. Nene's Game

JunKang 2024. 4. 14. 23:24

Problem details

https://codeforces.com/contest/1956/problem/A

Problem - A - Codeforces

codeforces.com

 

Ideas

  1. The a(1) is the smallest number of all a(k).
  2. All players of order greater than or equal to a(1) are kicked out.

 

Answer code (Java)

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int t, k, q, a;
		
		t = sc.nextInt();
		for (int i = 0; i < t; i++) {
			k = sc.nextInt();
			q = sc.nextInt();
			
			a = 0;
			for (int j = 0; j < k; j++) {
				if (a == 0) a = sc.nextInt();	// The a(1) is the smallest number of all a(k).
				else sc.nextInt();
			}
			
			for (int j = 0; j < q; j++) {
				System.out.print(Math.min(a - 1, sc.nextInt()) + " ");	// All players of order greater than n(i) are kicked out.
			}
			System.out.println();
		}
	}
}