공부기록/백준

[백준] 1026번 보물

메델 2024. 1. 8. 10:38
import java.util.*;

public class Main
{

    public static void main(String[] args)
    {
        Scanner kb = new Scanner(System.in);
        
        int n = kb.nextInt();
        
        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();
        
        for(int i=0; i<n; i++){
            list1.add(kb.nextInt());
        }
        
        Collections.sort(list1,Collections.reverseOrder());
        
        for(int i=0; i<n; i++){
            list2.add(kb.nextInt());
        }
        
        Collections.sort(list2);
        
        int sum = 0;
        
        for(int i=0; i<n; i++){
            sum += list1.get(i) * list2.get(i);
        }
        
        System.out.println(sum);
    }
}