문제

https://algospot.com/judge/problem/read/MATCHORDER

걸린 시간

00 : 19 : 28

풀이

C++

#include <bits/stdc++.h>
#define INF 987654321
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int tc;
    cin >> tc;
    while(tc--){
        int n, tmp;
        cin >> n;
        vector<int> rus, kor;
        for(int i = 0; i < n; i++){
            cin >> tmp;
            rus.push_back(tmp);
        }
        for(int i = 0; i < n; i++){
            cin >> tmp;
            kor.push_back(tmp);
        }
        sort(rus.begin(), rus.end());
        sort(kor.begin(), kor.end());
        int ans = 0;
        int last = 0;
        for(int i = 0; i < n; i++){ // rus
            for(int j = last; j < n; j++){ // kor
                last++;
                if(rus[i] <= kor[j]){
                    ans++;
                    break;
                }
            }
        }
        cout << ans << "\n";
    }
    return 0;
}

쉬운 난이도의 그리디 알고리즘 문제.

댓글