-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
11-kangrae-jo #41
11-kangrae-jo #41
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ λ²μ νμλ λμ ν© λ¬Έμ μ λΉμ·νλ€μ. μ λ μ΄μ€ forλ¬Έμ μ¬μ©νμ§ μκ³ νλ²μ νμ΄λ³΄μμ΅λλ€. dpλ₯Ό μ¬μ©ν μ½λλ μΈμμ μ΄λ€μ κ³ μνμ ¨μ΅λλ€~~
sort(arr, arr + n);
for (int i = 0; i < n; i++) ret += arr[i] * (n - i);
μ λ νμ΄λ³΄λ λμΌν μ½λλ‘ λμλ€μ Java codeimport java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] time = new int[n];
for (int i = 0; i < n; i++) {
time[i] = sc.nextInt();
}
Arrays.sort(time);
int result = time[0];
for (int i = 1; i < n; i++) {
time[i] = time[i] + time[i -1];
result += time[i];
}
System.out.println(result);
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λμ ν©μ λμ ν©μ΄λΌ λμ λ°°μ΄ λΉμ·νκ² νλ©΄ λ κ²κ°λ€κ³ μκ°νμ΅λλ€.
λ€λ§ μλ₯Ό μ ν΄μ£ΌκΈ°λλ¬Έμ λμ μ μλκ³ μ΄λ¦μ λΆμ΄μλ©΄ μ μ λ°°μ΄..?
n = int(input())
time = list(map(int, input().split()))
time.sort()
sum = 0
for i in range(len(time)-1):
time[i+1] = time[i] + time[i+1]
sum += time[i+1]
print(sum+time[0])
κ° λ°°μ΄μ μμλ₯Ό μ΄μ μμμ λμ ν©μΌλ‘ λ°κΏμ£Όκ³ , λ°λ³΅λ¬Έλ§λ€ sumλ³μμ ν©μ λν΄μ€λλ€.
π λ¬Έμ λ§ν¬
[ATM]
βοΈ μμλ μκ°
13m
β¨ μλ μ½λ
μνμ΄ κ±°μ λλκ°κ³ μ€λλ§μ κ°μ μ‘μλ³Ό κ²Έ μ¬μ΄ μ‘°κΈ μ¬μ΄ λ¬Έμ λ‘ μ€λΉνμ΅λλ€.
μ΄ λ¬Έμ λ₯Ό μμ½νμλ©΄ λ€μκ³Ό κ°μ΅λλ€.
μ΅μ κ°μ ꡬνκΈ° μν΄μλ μ°μ ATMμ μ¬μ©νλ μκ°μ΄ μ μ μ¬λ μμλλ‘ μ€μ μΈμμΌ νλ€.
μλνλ©΄ μκ°μ μ€λμ°λ μ¬λμ΄ μμ κ°λ€λ©΄, μ 체μ μΌλ‘ κΈ°λ€λ¦¬λ μκ°μ΄ λμ΄λκΈ° λλ¬Έμ΄λ€.
κ·Έ λ€μλ ꡬνμ λ¬Έμ μ΄λ€.
1λ²μ§Έ μ¬λκ³Ό 2λ²μ§Έ μ¬λ, .... λ§μ§λ§ μ¬λκΉμ§ κ°κ°μ μ¬λ i λ
1 ~ i-1 μ¬λμ΄ μ¬μ©ν μκ°λ§νΌ κΈ°λ€λ €μΌνλ€.
λ°λΌμ resultμλ 1 ~ i-1 μκ° + i μκ° (μ¦ 1~i μκ°)μ κ³μν΄μ λν΄μ£Όμ΄μΌνλ€.
κ·Έκ²μ μ½λλ‘ κ΅¬νν μ μλ€λ©΄ μ΄ λ¬Έμ λ μ½κ² ν΅κ³Όν κ²μ΄λ€!
κ·Έλ°λ°... λκ° λΉν¨μ¨ μ μ΄λΌλ μκ°μ΄ μ‘°κΈ λ€μμ΅λλ€.
λμμ λκ° μ΄κ±° dpλ‘ ν μ μμ κ²λ§ κ°μ λλμ΄ λ€μμ΅λλ€.
κ·Έλμ ν λ² νμ΄λ΄€μ΅λλ€~!
DP CODE
μ΄μ§ μ 맀νκΈ΄νμ§λ§ 2μ€ forλ¬Έμ κ³ μ³€λ€λ κ²μ μλ―Έκ° μλ κ² κ°μ΅λλ€.
κ°μ¬ν©λλ€
μν λ§μ§λ§κΉμ§ νμ΄ν ~
π μλ‘κ² μκ²λ λ΄μ©
.