# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1083762 |
2024-09-04T05:22:08 Z |
bvd |
Stove (JOI18_stove) |
Java 11 |
|
50 ms |
16160 KB |
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStream;
public class stove {
private static class Kattio extends PrintWriter {
public Kattio(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public Kattio(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public boolean hasMoreTokens() {
return peekToken() != null;
}
public int getInt() {
return Integer.parseInt(nextToken());
}
public double getDouble() {
return Double.parseDouble(nextToken());
}
public long getLong() {
return Long.parseLong(nextToken());
}
public String getWord() {
return nextToken();
}
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null)
return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) {
}
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
}
public static void main(String[] args) {
try(Kattio io = new Kattio(System.in, System.out)) {
int n = io.getInt();
int k = io.getInt();
if (k == n) {
io.println(n);
}
Integer[] gaps = new Integer[n-1];
int prevInt = -1;
int firstInt = -1;
for (int i=0; i<n; ++i) {
int curInt = io.getInt();
if (i>0) {
gaps[i-1] = curInt - prevInt - 1;
} else {
firstInt = curInt;
}
prevInt = curInt;
}
Arrays.sort(gaps, Collections.reverseOrder());
int result = prevInt + 1 - firstInt;
for (int i=0; i<k-1; ++i) {
result -= gaps[i];
}
io.println(result);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
14288 KB |
Output is correct |
2 |
Correct |
46 ms |
16012 KB |
Output is correct |
3 |
Correct |
49 ms |
14144 KB |
Output is correct |
4 |
Correct |
47 ms |
16160 KB |
Output is correct |
5 |
Incorrect |
50 ms |
13988 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
14288 KB |
Output is correct |
2 |
Correct |
46 ms |
16012 KB |
Output is correct |
3 |
Correct |
49 ms |
14144 KB |
Output is correct |
4 |
Correct |
47 ms |
16160 KB |
Output is correct |
5 |
Incorrect |
50 ms |
13988 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
14288 KB |
Output is correct |
2 |
Correct |
46 ms |
16012 KB |
Output is correct |
3 |
Correct |
49 ms |
14144 KB |
Output is correct |
4 |
Correct |
47 ms |
16160 KB |
Output is correct |
5 |
Incorrect |
50 ms |
13988 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |