https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5LsaaqDzYDFAXc
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Solution {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
for(int t=1; t<=T; t++) {
StringTokenizer tokens = new StringTokenizer(br.readLine());
int N = Integer.parseInt(tokens.nextToken()); // 방문자수
int M = Integer.parseInt(tokens.nextToken()); // M초에 걸쳐
int K = Integer.parseInt(tokens.nextToken()); // K개 완성
int [] arriveTime = new int[N];
tokens = new StringTokenizer(br.readLine());
for(int i=0; i<N; i++) {
//int idx = scanner.nextInt();
arriveTime[i] = Integer.parseInt(tokens.nextToken());// 도착 시간
}
Arrays.sort(arriveTime);
// 입력 처리 완료!
String result = "Possible";
for(int i=1; i<=N; i++) {
int time = arriveTime[i-1];
int bread = time/M*K-i; // 해당시점의 사람 수(i)만큼 빵을 사감
if(bread<0) {
result = "Impossible";
break;
}
}
sb.append(String.format("#%d %s%n",t, result));
}
System.out.println(sb);
}
static String src = "4\r\n" +
"2 2 2\r\n" +
"3 4\r\n" +
"2 2 2\r\n" +
"1 2\r\n" +
"2 2 1\r\n" +
"4 2\r\n" +
"2 2 1\r\n" +
"3 2";
}