먹을 것인가 먹힐 것인가 7795

LJM·2023년 1월 30일
0

백준풀기

목록 보기
65/259

https://www.acmicpc.net/problem/7795

import java.io.*;
import java.util.*;

public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int T = Integer.parseInt(br.readLine());

        int N,M;
        String[] input;
        Integer[] A,B;
        int ans;
        for(int i = 0; i < T; ++i)
        {
            ans = 0;
            input = br.readLine().split(" ");
            N = Integer.parseInt(input[0]);
            M = Integer.parseInt(input[1]);

            A = new Integer[N];
            B = new Integer[M];

            input = br.readLine().split(" ");
            for(int j = 0; j < N; ++j)
            {
                A[j] = Integer.parseInt(input[j]);
            }

            input = br.readLine().split(" ");
            for(int j = 0; j < M; ++j)
            {
                B[j] = Integer.parseInt(input[j]);
            }

            Arrays.sort(A, Collections.reverseOrder());
            Arrays.sort(B, Collections.reverseOrder());

            for(int j = 0; j < A.length; ++j)
            {
                for(int k = 0; k < B.length; ++k)
                {
                    if(A[j] > B[k])
                    {
                        ans+=B.length-k;
                        break;
                    }
                }
            }

            System.out.println(ans);
        }
    }
}
profile
게임개발자 백엔드개발자

0개의 댓글