답안 #716740

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
716740 2023-03-31T01:19:11 Z browntoad Stove (JOI18_stove) Java 11
컴파일 오류
0 ms 0 KB
import java.util.*;
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:2: error: class, interface, or enum expected
public static void main(String[] args) {
              ^
stove.java:4: error: class, interface, or enum expected
  int n, k;
  ^
stove.java:5: error: class, interface, or enum expected
  n = obj.nextInt();
  ^
stove.java:6: error: class, interface, or enum expected
  k = obj.nextInt();
  ^
stove.java:7: error: class, interface, or enum expected
  int arr[] = new int [n];
  ^
stove.java:8: error: class, interface, or enum expected
  for (int i=0; i<n; i++){
  ^
stove.java:8: error: class, interface, or enum expected
  for (int i=0; i<n; i++){
                ^
stove.java:8: error: class, interface, or enum expected
  for (int i=0; i<n; i++){
                     ^
stove.java:10: error: class, interface, or enum expected
  }
  ^
stove.java:12: error: class, interface, or enum expected
  if (n == 1){
  ^
stove.java:14: error: class, interface, or enum expected
    return;
    ^
stove.java:15: error: class, interface, or enum expected
  }
  ^
stove.java:17: error: class, interface, or enum expected
  for (int i=0; i<n-1; i++){
  ^
stove.java:17: error: class, interface, or enum expected
  for (int i=0; i<n-1; i++){
                ^
stove.java:17: error: class, interface, or enum expected
  for (int i=0; i<n-1; i++){
                       ^
stove.java:19: error: class, interface, or enum expected
  }
  ^
stove.java:20: error: class, interface, or enum expected
  for (int i=0; i<n-2; i++){
                ^
stove.java:20: error: class, interface, or enum expected
  for (int i=0; i<n-2; i++){
                       ^
stove.java:22: error: class, interface, or enum expected
    for (int j=i+1; j<n-1; j++){
    ^
stove.java:22: error: class, interface, or enum expected
    for (int j=i+1; j<n-1; j++){
                    ^
stove.java:22: error: class, interface, or enum expected
    for (int j=i+1; j<n-1; j++){
                           ^
stove.java:25: error: class, interface, or enum expected
      }
      ^
stove.java:28: error: class, interface, or enum expected
    sarr[id] = sarr[i];
    ^
stove.java:29: error: class, interface, or enum expected
    sarr[i] = tmp;
    ^
stove.java:30: error: class, interface, or enum expected
  }
  ^
stove.java:31: error: class, interface, or enum expected
  for(int i=0; i<n-k; i++){
               ^
stove.java:31: error: class, interface, or enum expected
  for(int i=0; i<n-k; i++){
                      ^
stove.java:33: error: class, interface, or enum expected
  }
  ^
stove.java:36: error: class, interface, or enum expected
}
^
29 errors