olrlobt
[μλ°/λ°±μ€ κ³¨λ3] #13904 κ³Όμ λ³Έλ¬Έ
π 골λ3 - #13904 κ³Όμ
π ν μ€νΈμΌμ΄μ€ μΆκ° ννΈ
4
1 10
3 30
3 30
3 40
= 100
βοΈ νμ΄λ²
λ¬Έμ λ μ λ§ κ°λ¨νλ€κ³ μκ°νλ€.
λ§κ°μΌλΆν° κ±°κΎΈλ‘ μ§νμ νκ³ , μ΅λκ°λΆν° νλμ© λΉΌ μ£Όλ λ°©μμΌλ‘ ν΄κ²°νμλ€.
μ ν μ€νΈ μΌμ΄μ€λ‘ μ€λͺ μ νμλ©΄,
3μΌμ μν κ°λ₯ν κ³Όμ = ( 30 , 30 , 40) / 40 μν
2μΌμ μν κ°λ₯ν κ³Όμ = ( 30, 30) / 30 μν
1μΌμ μν κ°λ₯ν κ³Όμ = ( 30 , 10) / 30 μν
= 100
νμ΄ λ°©λ²:
1. λ§κ°μΌ μμ μ΅λκ°λΆν° ν΄λΉ λ μλ§ μν κ°λ₯ν κ³Όμ λ₯Ό μν κ°λ₯ 리μ€νΈμ μΆκ°νλ€.
2. μν κ°λ₯ 리μ€νΈμμ μ΅λκ°μ μ κ±°νκ³ , μ΅μ’ μ μμ λνλ€.
3. μ΅λκ°μμ 1μ λΊ ν, μ κ³Όμ μ λ°λ³΅νλ€.
ποΈ νμ΄
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class baekjoon13904 {
static List<int[]> task = new ArrayList<>();
static List<Integer> usableTask = new ArrayList<>();
static int max = 0;
static int maxScore = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
for (int testCase = 0; testCase < N; testCase++) {
int d = sc.nextInt();
int w = sc.nextInt();
if (max < d) {
max = d;
}
int[] P = {d, w};
task.add(P);
}
solve();
System.out.println(maxScore);
}
public static void solve() {
while (max != 0) {
setUsableTask();
setAssignTask();
}
}
private static void setAssignTask() {
if (usableTask.size() != 0) {
Integer maxValue = usableTask.stream()
.max(Comparator.comparing(x -> x))
.orElseThrow(NoSuchElementException::new);
usableTask.remove(maxValue);
maxScore += maxValue;
}
max--;
}
private static void setUsableTask() {
for (int i = 0; i < task.size(); i++) {
if (task.get(i)[0] >= max) {
usableTask.add(task.get(i)[1]);
task.remove(task.get(i));
i--;
}
}
}
}
'Algorithm > λ°±μ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[μλ°/λ°±μ€ κ³¨λ5] #1461 λμκ΄ (1) | 2023.01.02 |
---|---|
[μλ°/λ°±μ€ κ³¨λ5] #13164 ν볡 μ μΉμ (1) | 2023.01.01 |
[μλ°/λ°±μ€ κ³¨λ4] #1715 μΉ΄λ μ λ ¬νκΈ° (0) | 2022.12.31 |
[μλ°/λ°±μ€ κ³¨λ2] #2437 μ μΈ (1) | 2022.12.31 |
[μλ°/λ°±μ€ κ³¨λ5] #12904 Aμ B (0) | 2022.12.31 |
Comments