BOJ_S3_11399
π [S3_11399] ATM
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
public class Main{
static StringTokenizer st;
public static void main(String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
// μ¬λ μ
int N = Integer.parseInt(br.readLine());
// μ¬λ λ°°μ΄
ArrayList<Integer> list = new ArrayList<Integer>();
st = new StringTokenizer(br.readLine(), " ");
for(int i=0; i<N; i++){
list.add(Integer.parseInt(st.nextToken()));
}
Collections.sort(list);
int sum = 0;
int idx = 1;
while(idx<N+1){
for(int i=0; i<idx;i++){
sum += list.get(i);
}
idx++;
}
sb.append(sum);
System.out.println(sb);
}
}
π€ λμ μκ°
μ΄ λ¬Έμ λ TestCaseλ₯Ό 보면μ κ·μΉμ μ°Ύμλλ€.
μ λ ¬μ ν΄μ μμ μλΆν° μ€μ²©μΌλ‘ λν΄κ°λ©΄ κ°μ₯ μ μ μκ°μ΄ κ±Έλ¦°λ€λ κ²μ..
κ·Έλμ ArrayListλ‘ μ
λ ₯ λ°μ μ λ ¬νκ³ μμλλ‘ λν΄μ£Όκ³ λ μ€μ²©ν΄μ λν΄μ£Όκ³ νμλ€.