https://www.acmicpc.net/problem/1246
1246번: 온라인 판매
첫째 줄에 정수 N(1 ≤ N ≤ 1,000)과 M(1 ≤ M ≤ 1,000)이 입력된다. 둘째 줄부터 M+1번째 줄까지 i+1번째 줄에는 Pi(1 ≤ Pi ≤ 1,000,000)가 입력된다.
www.acmicpc.net
import java.util.Scanner;
import java.util.Arrays;
public class feb19 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
int N=s.nextInt(); //알 갯수
int M=s.nextInt(); //고객 수
int arr[]=new int[M];
for(int i=0;i<M;i++) {
arr[i]=s.nextInt();
}
s.close();
Arrays.sort(arr);
int cost=0;
int max=0;
for(int i=0;i<M;i++) {
int total=0;
if((M-i)<N) {
total=arr[i]*(M-i);
}else {
total=arr[i]*N;
}
if(total>max) {
max=total;
cost=arr[i];
}
}
System.out.print(cost+" "+max);
}
}

이야...
'JAVA' 카테고리의 다른 글
[백준/자바] 18228번 펭귄추락대책위원회 (0) | 2022.02.21 |
---|---|
[백준/자바] 22864번 피로도 (0) | 2022.02.20 |
[백준/자바] 19947번 투자의 귀재 배주형 (0) | 2022.02.18 |
[백준/자바] 9655번 돌 게임 (0) | 2022.02.17 |
[백준/자바] 14916번 거스름돈 (0) | 2022.02.16 |
댓글