Submission #716742

# Submission time Handle Problem Language Result Execution time Memory
716742 2023-03-31T01:20:30 Z browntoad Stove (JOI18_stove) C++14
Compilation error
0 ms 0 KB
import java.util.*;

public 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

stove.cpp:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
stove.cpp:3:1: error: expected unqualified-id before 'public'
    3 | public class stove
      | ^~~~~~