olrlobt

[μžλ°”/λ°±μ€€ κ³¨λ“œ3] #13904 과제 λ³Έλ¬Έ

Algorithm/λ°±μ€€

[μžλ°”/λ°±μ€€ κ³¨λ“œ3] #13904 과제

olrlobt 2022. 12. 31. 14:54

πŸ”’ κ³¨λ“œ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--;
            }
        }
    }
}
Comments