-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCF158ANextRound.java
More file actions
41 lines (37 loc) · 1.33 KB
/
CF158ANextRound.java
File metadata and controls
41 lines (37 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
/**
* See <a href="http://codeforces.com/problemset/problem/158/A">Next Round</a>
* @author Brian Yeicol Restrepo Tangarife
*/
public class CF158ANextRound {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
String[] line1 = in.readLine().split("\\s");
byte k = Byte.parseByte(line1[0]);
byte n = Byte.parseByte(line1[1]);
byte participants = n;
String[] line2 = in.readLine().split("\\s");
int[] a = Arrays.stream(line2).mapToInt(Integer::parseInt).sorted().toArray();
byte basePosition = (byte) (k - n);
byte baseEscore = (byte) a[basePosition];
if (baseEscore == 0) {
while (basePosition < k && a[basePosition] == 0) {
participants--;
basePosition++;
}
} else {
basePosition--;
while (basePosition >= 0 && a[basePosition] == baseEscore) {
participants++;
basePosition--;
}
}
out.println(participants);
out.close();
}
}