Study/Problem Solving

[BOJ_1758] 알바생 강호

monitor 2024. 3. 29. 19:40

설명


코드를 간결하게 짜려고 노력했습니다. 사실 실버 4 문제라서 크게 설명이 필요 없을 듯하고 해서 최대한 간결한 형태로 짜봤습니다.

 

코드


package BOJ.greedy;

import java.util.*;

public class BOJ_1758 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        List<Long> arr = new ArrayList<>();
        for (int i = 0; i < N; i++){
            arr.add(sc.nextLong());
        }
        arr.sort(Comparator.reverseOrder());
        long ans = 0;
        for (int i = 0; i < arr.size(); i++){
            ans += Math.max((arr.get(i) - i), 0);
        }
        System.out.println(ans);
    }
}​

 

 

1758번: 알바생 강호

첫째 줄에 스타박스 앞에 서 있는 사람의 수 N이 주어진다. N은 100,000보다 작거나 같은 자연수이다. 둘째 줄부터 총 N개의 줄에 각 사람이 주려고 하는 팁이 주어진다. 팁은 100,000보다 작거나 같

www.acmicpc.net