algorithm study
[소프티어] 마이크로 서버 / C++ 해설
dongha
2022. 12. 3. 02:52
더 많은 문제풀이는 아래 Github 주소에서 확인하실 수 있습니다.
https://github.com/Dongha-k/softeer-code
GitHub - Dongha-k/softeer-code: softeer 문제 풀이입니다.
softeer 문제 풀이입니다. Contribute to Dongha-k/softeer-code development by creating an account on GitHub.
github.com
문제 출처: https://softeer.ai/practice/info.do?idx=1&eid=628
Softeer
연습문제를 담을 Set을 선택해주세요. 취소 확인
softeer.ai
공식 해설: https://softeer.ai/community/view.do?idx=685&cd=edu&pageNo=1
Softeer
아직 태그 없음 --> [2021년 재직자 대회 예선] 마이크로 서버 Softeer 관리자 1285 views · 2021-12-29 11:26 0 즐겨찾기
softeer.ai
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char** argv)
{
int test_case = 0;
cin >> test_case;
for(int t = 0 ; t < test_case ; t ++){
int n;
int result = 0;
cin >> n;
vector<int> service(n);
for(int i = 0 ; i < n ; i ++) cin >> service[i];
sort(service.begin(), service.end());
// 300 <= service[i] <= 900
int cnt = 0;
for(int i = 0 ; i < n ; i ++){
if(service[i] != 300) break;
cnt ++;
}
int start = cnt;
int end = n - 1;
while(start <= end){
if(service[end] > 600){
result ++;
end --;
}
else if(service[end] == 600){
if(cnt > 0) {
result ++;
end --;
cnt --;
}
else {
result ++;
end --;
}
}
else if(start != end and 300 < service[end] and service[end] < 600){
if(service[start] + service[end] <= 900) {
result ++;
end --;
start ++;
}
else if(cnt > 0){
result ++;
end --;
cnt --;
}
else{
result ++;
end --;
}
}
else if(start == end and 300 < service[end] and service[end] < 600) {
if(cnt > 0){
result ++;
end --;
cnt --;
}
else{
result ++;
end --;
}
}
else break;
}
result += (cnt / 3);
if(cnt % 3 != 0) result ++;
cout << result << '\n';
}
return 0;
}