Submission #724565

# Submission time Handle Problem Language Result Execution time Memory
724565 2023-04-15T14:34:11 Z browntoad Stove (JOI18_stove) C++14
Compilation error
0 ms 0 KB
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class stove {
    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.cpp:1:1: error: 'import' does not name a type
    1 | import java.util.ArrayList;
      | ^~~~~~
stove.cpp:2:1: error: 'import' does not name a type
    2 | import java.util.Collections;
      | ^~~~~~
stove.cpp:3:1: error: 'import' does not name a type
    3 | import java.util.Scanner;
      | ^~~~~~
stove.cpp:6:11: error: expected ':' before 'static'
    6 |     public static void main(String[] args){
      |           ^~~~~~~
      |           :
stove.cpp:6:29: error: 'String' has not been declared
    6 |     public static void main(String[] args){
      |                             ^~~~~~
stove.cpp:6:38: error: expected ',' or '...' before 'args'
    6 |     public static void main(String[] args){
      |                                      ^~~~
stove.cpp:32:2: error: expected ';' after class definition
   32 | }
      |  ^
      |  ;
stove.cpp: In static member function 'static void stove::main(int*)':
stove.cpp:7:9: error: 'Scanner' was not declared in this scope
    7 |         Scanner scanner = new Scanner(System.in);
      |         ^~~~~~~
stove.cpp:8:17: error: 'scanner' was not declared in this scope
    8 |         int N = scanner.nextInt();
      |                 ^~~~~~~
stove.cpp:11:9: error: 'ArrayList' was not declared in this scope
   11 |         ArrayList<Integer> times = new ArrayList<>();
      |         ^~~~~~~~~
stove.cpp:11:19: error: 'Integer' was not declared in this scope
   11 |         ArrayList<Integer> times = new ArrayList<>();
      |                   ^~~~~~~
stove.cpp:11:28: error: 'times' was not declared in this scope
   11 |         ArrayList<Integer> times = new ArrayList<>();
      |                            ^~~~~
stove.cpp:11:40: error: 'ArrayList' does not name a type
   11 |         ArrayList<Integer> times = new ArrayList<>();
      |                                        ^~~~~~~~~
stove.cpp:11:50: error: expected primary-expression before '>' token
   11 |         ArrayList<Integer> times = new ArrayList<>();
      |                                                  ^
stove.cpp:11:52: error: expected primary-expression before ')' token
   11 |         ArrayList<Integer> times = new ArrayList<>();
      |                                                    ^
stove.cpp:19:28: error: 'diffTimes' was not declared in this scope
   19 |         ArrayList<Integer> diffTimes = new ArrayList<>();
      |                            ^~~~~~~~~
stove.cpp:19:44: error: 'ArrayList' does not name a type
   19 |         ArrayList<Integer> diffTimes = new ArrayList<>();
      |                                            ^~~~~~~~~
stove.cpp:19:54: error: expected primary-expression before '>' token
   19 |         ArrayList<Integer> diffTimes = new ArrayList<>();
      |                                                      ^
stove.cpp:19:56: error: expected primary-expression before ')' token
   19 |         ArrayList<Integer> diffTimes = new ArrayList<>();
      |                                                        ^
stove.cpp:24:9: error: 'Collections' was not declared in this scope
   24 |         Collections.sort(diffTimes);
      |         ^~~~~~~~~~~
stove.cpp:30:9: error: 'System' was not declared in this scope
   30 |         System.out.println(length - sum);
      |         ^~~~~~