Submission #716743

#TimeUsernameProblemLanguageResultExecution timeMemory
716743browntoadStove (JOI18_stove)C++14
Compilation error
0 ms0 KiB
import java.util.*; class Stove { public static void main(String[] args) { Scanner obj = new Scanner(System.in); int n, k; n = obj.nextInt(); k = obj.nextInt(); int arr[] = new int [n]; for (int i=0; i<n; i++){ arr[i] = obj.nextInt(); } int ans = n; if (n == 1){ System.out.println(ans); return; } int sarr[] = new int[n-1]; for (int i=0; i<n-1; i++){ sarr[i] = arr[i+1]-arr[i]-1; } for (int i=0; i<n-2; i++){ int id = i; for (int j=i+1; j<n-1; j++){ if (sarr[j]<sarr[id]){ id=j; } } int tmp = sarr[id]; sarr[id] = sarr[i]; sarr[i] = tmp; } for(int i=0; i<n-k; i++){ ans += sarr[i]; } System.out.println(ans); } }

Compilation message (stderr)

stove.cpp:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
stove.cpp:5:8: error: expected ':' before 'static'
    5 |  public static void main(String[] args) {
      |        ^~~~~~~
      |        :
stove.cpp:5:26: error: 'String' has not been declared
    5 |  public static void main(String[] args) {
      |                          ^~~~~~
stove.cpp:5:35: error: expected ',' or '...' before 'args'
    5 |  public static void main(String[] args) {
      |                                   ^~~~
stove.cpp:40:2: error: expected ';' after class definition
   40 | }
      |  ^
      |  ;
stove.cpp: In static member function 'static void Stove::main(int*)':
stove.cpp:6:3: error: 'Scanner' was not declared in this scope
    6 |   Scanner obj = new Scanner(System.in);
      |   ^~~~~~~
stove.cpp:8:7: error: 'obj' was not declared in this scope
    8 |   n = obj.nextInt();
      |       ^~~
stove.cpp:10:15: error: initializer fails to determine size of 'arr'
   10 |   int arr[] = new int [n];
      |               ^~~~~~~~~~~
stove.cpp:10:15: error: array must be initialized with a brace-enclosed initializer
stove.cpp:16:7: error: 'System' was not declared in this scope
   16 |       System.out.println(ans);
      |       ^~~~~~
stove.cpp:19:16: error: initializer fails to determine size of 'sarr'
   19 |   int sarr[] = new int[n-1];
      |                ^~~~~~~~~~~~
stove.cpp:19:16: error: array must be initialized with a brace-enclosed initializer
stove.cpp:37:3: error: 'System' was not declared in this scope
   37 |   System.out.println(ans);
      |   ^~~~~~