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);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
10224 KB |
Output is correct |
2 |
Correct |
101 ms |
10196 KB |
Output is correct |
3 |
Correct |
114 ms |
10108 KB |
Output is correct |
4 |
Correct |
107 ms |
9976 KB |
Output is correct |
5 |
Correct |
98 ms |
10052 KB |
Output is correct |
6 |
Correct |
94 ms |
10076 KB |
Output is correct |
7 |
Correct |
112 ms |
10132 KB |
Output is correct |
8 |
Correct |
115 ms |
10072 KB |
Output is correct |
9 |
Correct |
91 ms |
10176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
10224 KB |
Output is correct |
2 |
Correct |
101 ms |
10196 KB |
Output is correct |
3 |
Correct |
114 ms |
10108 KB |
Output is correct |
4 |
Correct |
107 ms |
9976 KB |
Output is correct |
5 |
Correct |
98 ms |
10052 KB |
Output is correct |
6 |
Correct |
94 ms |
10076 KB |
Output is correct |
7 |
Correct |
112 ms |
10132 KB |
Output is correct |
8 |
Correct |
115 ms |
10072 KB |
Output is correct |
9 |
Correct |
91 ms |
10176 KB |
Output is correct |
10 |
Correct |
313 ms |
14876 KB |
Output is correct |
11 |
Correct |
303 ms |
15016 KB |
Output is correct |
12 |
Correct |
340 ms |
14900 KB |
Output is correct |
13 |
Correct |
301 ms |
14920 KB |
Output is correct |
14 |
Correct |
307 ms |
14984 KB |
Output is correct |
15 |
Correct |
303 ms |
14888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
10224 KB |
Output is correct |
2 |
Correct |
101 ms |
10196 KB |
Output is correct |
3 |
Correct |
114 ms |
10108 KB |
Output is correct |
4 |
Correct |
107 ms |
9976 KB |
Output is correct |
5 |
Correct |
98 ms |
10052 KB |
Output is correct |
6 |
Correct |
94 ms |
10076 KB |
Output is correct |
7 |
Correct |
112 ms |
10132 KB |
Output is correct |
8 |
Correct |
115 ms |
10072 KB |
Output is correct |
9 |
Correct |
91 ms |
10176 KB |
Output is correct |
10 |
Correct |
313 ms |
14876 KB |
Output is correct |
11 |
Correct |
303 ms |
15016 KB |
Output is correct |
12 |
Correct |
340 ms |
14900 KB |
Output is correct |
13 |
Correct |
301 ms |
14920 KB |
Output is correct |
14 |
Correct |
307 ms |
14984 KB |
Output is correct |
15 |
Correct |
303 ms |
14888 KB |
Output is correct |
16 |
Execution timed out |
1022 ms |
18144 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |