답안 #724530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
724530 2023-04-15T13:45:26 Z vjudge1 Stove (JOI18_stove) Java 11
컴파일 오류
0 ms 0 KB
public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();

        ArrayList<Integer> times = new ArrayList<>();

        for (int i = 0; i < N; i++) {
            int arrival = scanner.nextInt();
            times.add(arrival);
        }
        int length = times.get(N-1) + 1 - times.get(0);

        ArrayList<Integer> diffTimes = new ArrayList<>();
        for (int i=1; i < times.size(); i++) {
            diffTimes.add(times.get(i) - times.get(i-1) - 1);
        }

        Collections.sort(diffTimes);

        int sum = 0;
        for (int i = N-K; i < N-1; i++) {
            sum += diffTimes.get(i);
        }
        System.out.println(length - sum);
    }

Compilation message

stove.java:1: error: class, interface, or enum expected
public static void main(String[] args){
              ^
stove.java:3: error: class, interface, or enum expected
        int N = scanner.nextInt();
        ^
stove.java:4: error: class, interface, or enum expected
        int K = scanner.nextInt();
        ^
stove.java:6: error: class, interface, or enum expected
        ArrayList<Integer> times = new ArrayList<>();
        ^
stove.java:8: error: class, interface, or enum expected
        for (int i = 0; i < N; i++) {
        ^
stove.java:8: error: class, interface, or enum expected
        for (int i = 0; i < N; i++) {
                        ^
stove.java:8: error: class, interface, or enum expected
        for (int i = 0; i < N; i++) {
                               ^
stove.java:10: error: class, interface, or enum expected
            times.add(arrival);
            ^
stove.java:11: error: class, interface, or enum expected
        }
        ^
stove.java:14: error: class, interface, or enum expected
        ArrayList<Integer> diffTimes = new ArrayList<>();
        ^
stove.java:15: error: class, interface, or enum expected
        for (int i=1; i < times.size(); i++) {
        ^
stove.java:15: error: class, interface, or enum expected
        for (int i=1; i < times.size(); i++) {
                      ^
stove.java:15: error: class, interface, or enum expected
        for (int i=1; i < times.size(); i++) {
                                        ^
stove.java:17: error: class, interface, or enum expected
        }
        ^
stove.java:21: error: class, interface, or enum expected
        int sum = 0;
        ^
stove.java:22: error: class, interface, or enum expected
        for (int i = N-K; i < N-1; i++) {
        ^
stove.java:22: error: class, interface, or enum expected
        for (int i = N-K; i < N-1; i++) {
                          ^
stove.java:22: error: class, interface, or enum expected
        for (int i = N-K; i < N-1; i++) {
                                   ^
stove.java:24: error: class, interface, or enum expected
        }
        ^
stove.java:26: error: class, interface, or enum expected
    }
    ^
20 errors