Submission #724567

# Submission time Handle Problem Language Result Execution time Memory
724567 2023-04-15T14:34:36 Z browntoad Stove (JOI18_stove) Java 11
0 / 100
161 ms 12272 KB
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main {
    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);
    }
}
# Verdict Execution time Memory Grader output
1 Runtime error 161 ms 12272 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 161 ms 12272 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 161 ms 12272 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -