[D3] 진기의 최고급 붕어빵 - 1860
성능 요약
메모리: 80,076 KB, 시간: 425 ms, 코드길이: 1,143 Bytes
제출 일자
2023-10-28 16:16
출처: SW Expert Academy, https://swexpertacademy.com/main/code/problem/problemList.do
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.*;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int tc = 1; tc <= T; tc++)
{
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int [] customers = new int[n];
for(int i = 0; i <n ; i++){
customers[i] = sc.nextInt();
}
Arrays.sort(customers);
int time = 0;
int makeTime = 0,makeCount = 0;
int idx = 0;
String result = "Possible";
while(time <= customers[n-1]){
if(makeTime == m){
makeCount += k;
makeTime = 0;
}
if(customers[idx] == time){
makeCount--;
idx++;
}
if(makeCount < 0){
result = "Impossible";
break;
}
time++; makeTime++;
}
System.out.println("#" + tc + " " + result);
}
}
}
굳이 그럴 필요 없이 공식을 만들어서 계산해줘도 됨
import java.util.*;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int tc = 1; tc <= T; tc++)
{
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int [] customers = new int[n];
for(int i = 0; i <n ; i++){
customers[i] = sc.nextInt();
}
Arrays.sort(customers);
String result = "Possible";
for(int i = 0; i < customers.length; i++){
// 손님이 도착한 시간 / m * k -> 도착한 시간까지 만든 붕어빵 개수
// i 먼저 온 손님들의 수(만큼 붕어빵을 빼줬는데 1보다 작다면 살 게 없음)
if((customers[i] / m * k) - i < 1){
result = "Impossible";
break;
}
}
System.out.println("#" + tc + " " + result);
}
}
}
'알고리즘 - SWEA > D3' 카테고리의 다른 글
[SW expert Academy] SWEA 13428번 숫자 조작 자바(Java) (0) | 2023.10.28 |
---|---|
[SW expert Academy] SWEA 135247번 팔씨름 자바(Java) (0) | 2023.10.28 |
[SW expert Academy] SWEA 2814번 최장경로 자바(Java) (0) | 2023.10.28 |
[SW expert Academy] SWEA 1216번 회문2 자바(Java) (0) | 2023.10.28 |
[SW expert Academy] SWEA 5601번 쥬스 나누기 자바(Java) (1) | 2023.10.28 |