-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathF.java
More file actions
87 lines (79 loc) · 2.34 KB
/
Copy pathF.java
File metadata and controls
87 lines (79 loc) · 2.34 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.io.IOException;
import java.io.InputStream;
public class F {
public static void main(String[] args) throws Exception {
FastScanner fs = new FastScanner(System.in);
Integer nObj = fs.nextIntNullable();
if (nObj == null) {
return;
}
int n = nObj;
int[] a = new int[n];
for (int i = 0; i < n; i++) {
Integer v = fs.nextIntNullable();
if (v == null) {
return;
}
a[i] = v;
}
int left = 1, right = n, answer = 0;
while (left <= right) {
int mid = left + (right - left) / 2;
if (existsBeautiful(a, mid)) {
answer = mid;
left = mid + 1;
} else {
right = mid - 1;
}
}
System.out.println(answer);
}
static boolean existsBeautiful(int[] a, int k) {
int consecutive = 0;
for (int val : a) {
if (val >= k) {
consecutive++;
if (consecutive >= k) return true;
} else {
consecutive = 0;
}
}
return false;
}
static class FastScanner {
private final InputStream in;
private final byte[] buffer = new byte[1 << 16];
private int ptr = 0, len = 0;
FastScanner(InputStream is) { this.in = is; }
private int read() throws IOException {
if (ptr >= len) {
len = in.read(buffer);
ptr = 0;
if (len <= 0) return -1;
}
return buffer[ptr++];
}
Integer nextIntNullable() throws IOException {
int c;
do {
c = read();
if (c == -1) return null;
} while (c <= ' ');
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int val = 0;
while (c > ' ') {
if (c < '0' || c > '9') {
while (c > ' ') c = read();
break;
}
val = val * 10 + (c - '0');
c = read();
}
return val * sgn;
}
}
}