Submission #716738

# Submission time Handle Problem Language Result Execution time Memory
716738 2023-03-31T01:10:51 Z vjudge1 Stove (JOI18_stove) Java 11
Compilation error
0 ms 0 KB
import java.util.*;

public class Main
{
	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.java:3: error: class Main is public, should be declared in a file named Main.java
public class Main
       ^
1 error