SW Expert Academy
(SWEA c++)1860. 진기의 최고급 붕어빵
naeunchan
2020. 10. 20. 09:28
728x90
반응형
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
손님이 들어오는 초를 vector에 저장하여 오름차순으로 정렬한다.
for문을 돌면서
K * (guest[j] / M) < j + 1보다 작으면 붕어빵이 없다는 뜻이므로 ans를 false로 바꿔 break.
ans의 값에 따라 "Possible", "Impossible"을 출력하면 된다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{
int t;
cin >> t;
for(int i = 1; i <= t; i++)
{
int N, M, K;
vector<int> guest;
bool ans = true;
cin >> N >> M >> K;
for(int j = 0; j < N; j++)
{
int tmp;
cin >> tmp;
guest.push_back(tmp);
}
sort(guest.begin(), guest.end());
for(int j = 0; j < N; j++)
{
if(K * (guest[j] / M) < j + 1)
{
ans = false;
break;
}
}
if(ans)
cout << "#" << i << " Possible" << endl;
else
cout << "#" << i << " Impossible" << endl;
}
return 0;
}728x90
반응형