• 문제 링크
14753번: MultiMax
There are n cards, each with an integer on it where two or more cards can have the same integer. From these cards, we want to select two or three cards such that the product of numbers on the selected cards is maximum. For example, assume that there are 6
www.acmicpc.net
• 풀이 과정
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
int[] arr = new int[n];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++)
arr[i] = Integer.parseInt(st.nextToken());
Arrays.sort(arr);
int max = Math.max(arr[--n] * arr[n - 1] * arr[n - 2], Math.max(arr[n] * arr[1] * arr[0], Math.max(arr[n] * arr[n - 1], arr[0] * arr[1])));
bw.write(String.valueOf(max));
bw.flush();
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 26596 황금 칵테일 - Data Structure / Java (0) | 2023.07.28 |
---|---|
[백준] 15577 Prosjek - Data Structure / Java (0) | 2023.07.27 |
[백준] 9417 최대 GCD - Brute Force / Java (0) | 2023.07.25 |
[백준] 5671 호텔 방 번호 - Brute Force / Java (0) | 2023.07.24 |
[백준] 13333 Q-인덱스 - Brute Force / Java (0) | 2023.07.23 |
댓글