알고리즘 문제풀이

Q1026 보물(java)

JihyunLee 2019. 9. 15. 13:06
반응형

 

도움을 얻은곳 : https://endorphin0710.tistory.com/73

 

[백준-1026] 보물 [java code]

https://www.acmicpc.net/problem/1026 [자바코드] import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.Scanner; public class S1026 { public static vo..

endorphin0710.tistory.com

 

내 코드(java)

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
 
public class Q1026{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        ArrayList<Integer> A = new ArrayList<>();
        ArrayList<Integer> B = new ArrayList<>();
        int N = scan.nextInt();
 
        for(int i=0; i<N; i++){
            A.add(scan.nextInt());
        }
        for(int i=0; i<N; i++){
            B.add(scan.nextInt());
        }
 
        Collections.sort(A);
        Collections.sort(B);
        Collections.reverse(B);
 
        int sum =0;
 
        for(int i=0; i<N; i++){
            sum += A.get(i) * B.get(i);
        }
 
        System.out.println(sum);
        
    }
}
cs
반응형