반응형
11399번: ATM
첫째 줄에 사람의 수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄에는 각 사람이 돈을 인출하는데 걸리는 시간 Pi가 주어진다. (1 ≤ Pi ≤ 1,000)
www.acmicpc.net
정렬 후 정렬된 값을 계단 식으로 더해 주었습니다.

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Main { | |
public static void main(String args[]) { | |
Scanner sc = new Scanner(System.in); | |
int N = sc.nextInt(); | |
int []person = new int[N]; | |
for(int i=0; i<N; i++) | |
person[i] = sc.nextInt(); | |
sc.close(); | |
Arrays.sort(person); | |
int result = 0; | |
for(int i=0; i<N; i++) | |
for(int j=0; j<=i; j++) | |
result+=person[j]; | |
System.out.print(result); | |
} | |
} |
반응형
'Algorithm' 카테고리의 다른 글
프로그래머스 코딩테스트 연습 Level2 - 기능개발 [ Java ] (0) | 2020.01.16 |
---|---|
백준 1541번 잃어버린 괄호 [ Java ] (0) | 2020.01.13 |
백준 1931번 회의실배정 [ Java ] (0) | 2020.01.12 |
백준 5086번 배수와 약수 [ Java ] (0) | 2020.01.09 |
프로그래머스 코딩테스트 연습 - 탑 [ Java ] (0) | 2020.01.09 |