알고리즘/백준 등

[백준] 보물

컵라면만두세트 2021. 2. 13. 17:18

내림차순 , 오름차순 이용하여 문제풀이

 

package silver4;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;

public class 보물1026 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Integer A[] = new Integer[N];
		Integer B[] = new Integer[N];
		for(int i =0; i<N; i++) {
			A[i] = sc.nextInt();
		} // a에 넣어주고 
		for(int i =0; i<N; i++) {
			B[i] = sc.nextInt();
		}
		Arrays.sort(A,Collections.reverseOrder()); // 오름차순
		Arrays.sort(B); // 내림차순 
		
		int result = 0 ;
		int ans = Integer.MAX_VALUE;
		int min = 0;
		for(int i = 0; i<N; i++) {
			result += A[i] * B[i];
			min = Math.min(result,ans);
		}
		System.out.println(min);
	
	}
}

 

'알고리즘 > 백준 등' 카테고리의 다른 글

DFS 예제  (0) 2021.02.18
[백준] 섬의개수  (0) 2021.02.17
[백준] 색종이  (0) 2021.02.09
[백준] 요세푸스 문제  (0) 2021.02.08
[백준] 카드 2  (0) 2021.02.05