# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
716744 | 2023-03-31T01:25:35 Z | browntoad | Stove (JOI18_stove) | C++14 | 0 ms | 0 KB |
import java.io.*; 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); } }