개발자 톡

연습문제 톡 [21년 재직자 대회 예선] 마이크로서버

마이크로서버 반례

등록일
2025-02-25 14:38:51
조회수
39
작성자
sungfire
#include<iostream>
#include<vector>
#include<algorithm>


using namespace std;


vector<int> v;
int T;
int ans;


int main(int argc, char** argv)
{
    cin >> T;
    for(int test_case = 0; test_case<T; test_case++)
        {
            int n;
            cin >> n;
            int ans1 = n;
            int ans2 = n;
            v.clear();
            v.resize(n);
            
            for(int i=0; i<n; i++)
                {
                    cin >> v[i];
                }
            sort(v.begin(), v.end());
            int start = 0;
            int end = n-1;
            
            while(start < end)
                {
                    
                    if(start+2 < n && v[start] + v[start+1] + v[start+2] == 900)
                        {
                            start+=3;
                            ans1-=2;
                        }
                    else if(v[start] + v[end] <=900)
                        {
                            start++;
                            end--;
                            ans1--;
                        }
                    else
                        {
                            end--;
                        }
                }
            start = 0;
            end = n-1;
            while(start < end)
                {
                    if(v[start] + v[end] <= 900)
                        {
                            start++;
                            end--;
                            ans2--;
                        }
                    else
                        {
                            end--;
                        }
                }
            cout << min(ans1, ans2) << "\n";
        }
return 0;



계속 25개만 맞는데 어떤 부분이 반례인지 모르겠습니다...

#[21년_재직자_대회_예선]_마이크로서버

이 카테고리의 톡 더보기