import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.ArrayList;
public class triusis { // any other name breaks the grader lmao
public static void main(String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer inital = new StringTokenizer(read.readLine());
int poleNum = Integer.parseInt(inital.nextToken());
int jumpHeight = Integer.parseInt(inital.nextToken());
ArrayList<Integer> possUnchanged = new ArrayList<>();
for (int p = 0; p < poleNum; p++) {
int pole = Integer.parseInt(read.readLine());
// only add if it has any hope of being unchanged
if ((p + 1) * jumpHeight >= pole) {
possUnchanged.add((p + 1) * jumpHeight - pole);
}
}
System.out.println(poleNum - longestNondecSubseq(possUnchanged));
}
private static int longestNondecSubseq(ArrayList<Integer> arr) {
ArrayList<Integer> minEndings = new ArrayList<>();
for (int i : arr) {
// find the latest spot we can insert it (because it just has to be nondecreasing)
int pos = bisectRight(minEndings, i);
// standard LIS protocol
if (pos == minEndings.size()) {
minEndings.add(i);
} else {
minEndings.set(pos, i);
}
}
return minEndings.size();
}
private static int bisectRight(ArrayList<Integer> arr, int x) {
int lo = 0;
int hi = arr.size();
while (lo < hi) {
int mid = (lo + hi) / 2;
if (x < arr.get(mid)) {
hi = mid;
} else {
lo = mid + 1;
}
}
return lo;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
8392 KB |
Output is correct |
2 |
Correct |
57 ms |
8568 KB |
Output is correct |
3 |
Correct |
68 ms |
8464 KB |
Output is correct |
4 |
Correct |
57 ms |
8400 KB |
Output is correct |
5 |
Correct |
58 ms |
8248 KB |
Output is correct |
6 |
Correct |
58 ms |
8352 KB |
Output is correct |
7 |
Correct |
59 ms |
8328 KB |
Output is correct |
8 |
Correct |
74 ms |
8344 KB |
Output is correct |
9 |
Correct |
63 ms |
8288 KB |
Output is correct |
10 |
Correct |
59 ms |
8420 KB |
Output is correct |
11 |
Correct |
60 ms |
8380 KB |
Output is correct |
12 |
Correct |
63 ms |
8188 KB |
Output is correct |
13 |
Correct |
65 ms |
8268 KB |
Output is correct |
14 |
Correct |
57 ms |
8380 KB |
Output is correct |
15 |
Correct |
59 ms |
8188 KB |
Output is correct |
16 |
Correct |
61 ms |
8204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
8392 KB |
Output is correct |
2 |
Correct |
57 ms |
8568 KB |
Output is correct |
3 |
Correct |
68 ms |
8464 KB |
Output is correct |
4 |
Correct |
57 ms |
8400 KB |
Output is correct |
5 |
Correct |
58 ms |
8248 KB |
Output is correct |
6 |
Correct |
58 ms |
8352 KB |
Output is correct |
7 |
Correct |
59 ms |
8328 KB |
Output is correct |
8 |
Correct |
74 ms |
8344 KB |
Output is correct |
9 |
Correct |
63 ms |
8288 KB |
Output is correct |
10 |
Correct |
59 ms |
8420 KB |
Output is correct |
11 |
Correct |
60 ms |
8380 KB |
Output is correct |
12 |
Correct |
63 ms |
8188 KB |
Output is correct |
13 |
Correct |
65 ms |
8268 KB |
Output is correct |
14 |
Correct |
57 ms |
8380 KB |
Output is correct |
15 |
Correct |
59 ms |
8188 KB |
Output is correct |
16 |
Correct |
61 ms |
8204 KB |
Output is correct |
17 |
Correct |
68 ms |
8504 KB |
Output is correct |
18 |
Correct |
58 ms |
8520 KB |
Output is correct |
19 |
Correct |
62 ms |
8244 KB |
Output is correct |
20 |
Correct |
107 ms |
8724 KB |
Output is correct |
21 |
Correct |
121 ms |
10048 KB |
Output is correct |
22 |
Correct |
135 ms |
11664 KB |
Output is correct |
23 |
Correct |
158 ms |
11996 KB |
Output is correct |
24 |
Correct |
162 ms |
12136 KB |
Output is correct |
25 |
Correct |
156 ms |
11924 KB |
Output is correct |
26 |
Correct |
182 ms |
12136 KB |
Output is correct |
27 |
Correct |
148 ms |
11808 KB |
Output is correct |
28 |
Correct |
189 ms |
11904 KB |
Output is correct |
29 |
Correct |
126 ms |
9880 KB |
Output is correct |
30 |
Correct |
158 ms |
11832 KB |
Output is correct |
31 |
Correct |
177 ms |
11800 KB |
Output is correct |
32 |
Correct |
164 ms |
11656 KB |
Output is correct |
33 |
Correct |
161 ms |
11988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
8504 KB |
Output is correct |
2 |
Correct |
58 ms |
8520 KB |
Output is correct |
3 |
Correct |
62 ms |
8244 KB |
Output is correct |
4 |
Correct |
107 ms |
8724 KB |
Output is correct |
5 |
Correct |
121 ms |
10048 KB |
Output is correct |
6 |
Correct |
135 ms |
11664 KB |
Output is correct |
7 |
Correct |
158 ms |
11996 KB |
Output is correct |
8 |
Correct |
162 ms |
12136 KB |
Output is correct |
9 |
Correct |
156 ms |
11924 KB |
Output is correct |
10 |
Correct |
182 ms |
12136 KB |
Output is correct |
11 |
Correct |
148 ms |
11808 KB |
Output is correct |
12 |
Correct |
189 ms |
11904 KB |
Output is correct |
13 |
Correct |
126 ms |
9880 KB |
Output is correct |
14 |
Correct |
158 ms |
11832 KB |
Output is correct |
15 |
Correct |
177 ms |
11800 KB |
Output is correct |
16 |
Correct |
164 ms |
11656 KB |
Output is correct |
17 |
Correct |
161 ms |
11988 KB |
Output is correct |
18 |
Correct |
58 ms |
8392 KB |
Output is correct |
19 |
Correct |
57 ms |
8568 KB |
Output is correct |
20 |
Correct |
68 ms |
8464 KB |
Output is correct |
21 |
Correct |
57 ms |
8400 KB |
Output is correct |
22 |
Correct |
58 ms |
8248 KB |
Output is correct |
23 |
Correct |
58 ms |
8352 KB |
Output is correct |
24 |
Correct |
59 ms |
8328 KB |
Output is correct |
25 |
Correct |
74 ms |
8344 KB |
Output is correct |
26 |
Correct |
63 ms |
8288 KB |
Output is correct |
27 |
Correct |
59 ms |
8420 KB |
Output is correct |
28 |
Correct |
60 ms |
8380 KB |
Output is correct |
29 |
Correct |
63 ms |
8188 KB |
Output is correct |
30 |
Correct |
65 ms |
8268 KB |
Output is correct |
31 |
Correct |
57 ms |
8380 KB |
Output is correct |
32 |
Correct |
59 ms |
8188 KB |
Output is correct |
33 |
Correct |
61 ms |
8204 KB |
Output is correct |
34 |
Correct |
135 ms |
11684 KB |
Output is correct |
35 |
Correct |
139 ms |
11532 KB |
Output is correct |
36 |
Correct |
139 ms |
11712 KB |
Output is correct |
37 |
Correct |
159 ms |
11872 KB |
Output is correct |
38 |
Correct |
147 ms |
11884 KB |
Output is correct |
39 |
Correct |
149 ms |
11788 KB |
Output is correct |
40 |
Correct |
170 ms |
11732 KB |
Output is correct |
41 |
Correct |
139 ms |
11720 KB |
Output is correct |
42 |
Correct |
154 ms |
11892 KB |
Output is correct |
43 |
Correct |
156 ms |
11972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
135 ms |
11684 KB |
Output is correct |
2 |
Correct |
139 ms |
11532 KB |
Output is correct |
3 |
Correct |
139 ms |
11712 KB |
Output is correct |
4 |
Correct |
159 ms |
11872 KB |
Output is correct |
5 |
Correct |
147 ms |
11884 KB |
Output is correct |
6 |
Correct |
149 ms |
11788 KB |
Output is correct |
7 |
Correct |
170 ms |
11732 KB |
Output is correct |
8 |
Correct |
139 ms |
11720 KB |
Output is correct |
9 |
Correct |
154 ms |
11892 KB |
Output is correct |
10 |
Correct |
156 ms |
11972 KB |
Output is correct |
11 |
Correct |
68 ms |
8504 KB |
Output is correct |
12 |
Correct |
58 ms |
8520 KB |
Output is correct |
13 |
Correct |
62 ms |
8244 KB |
Output is correct |
14 |
Correct |
107 ms |
8724 KB |
Output is correct |
15 |
Correct |
121 ms |
10048 KB |
Output is correct |
16 |
Correct |
135 ms |
11664 KB |
Output is correct |
17 |
Correct |
158 ms |
11996 KB |
Output is correct |
18 |
Correct |
162 ms |
12136 KB |
Output is correct |
19 |
Correct |
156 ms |
11924 KB |
Output is correct |
20 |
Correct |
182 ms |
12136 KB |
Output is correct |
21 |
Correct |
148 ms |
11808 KB |
Output is correct |
22 |
Correct |
189 ms |
11904 KB |
Output is correct |
23 |
Correct |
126 ms |
9880 KB |
Output is correct |
24 |
Correct |
158 ms |
11832 KB |
Output is correct |
25 |
Correct |
177 ms |
11800 KB |
Output is correct |
26 |
Correct |
164 ms |
11656 KB |
Output is correct |
27 |
Correct |
161 ms |
11988 KB |
Output is correct |
28 |
Correct |
58 ms |
8392 KB |
Output is correct |
29 |
Correct |
57 ms |
8568 KB |
Output is correct |
30 |
Correct |
68 ms |
8464 KB |
Output is correct |
31 |
Correct |
57 ms |
8400 KB |
Output is correct |
32 |
Correct |
58 ms |
8248 KB |
Output is correct |
33 |
Correct |
58 ms |
8352 KB |
Output is correct |
34 |
Correct |
59 ms |
8328 KB |
Output is correct |
35 |
Correct |
74 ms |
8344 KB |
Output is correct |
36 |
Correct |
63 ms |
8288 KB |
Output is correct |
37 |
Correct |
59 ms |
8420 KB |
Output is correct |
38 |
Correct |
60 ms |
8380 KB |
Output is correct |
39 |
Correct |
63 ms |
8188 KB |
Output is correct |
40 |
Correct |
65 ms |
8268 KB |
Output is correct |
41 |
Correct |
57 ms |
8380 KB |
Output is correct |
42 |
Correct |
59 ms |
8188 KB |
Output is correct |
43 |
Correct |
61 ms |
8204 KB |
Output is correct |
44 |
Correct |
246 ms |
23164 KB |
Output is correct |
45 |
Correct |
187 ms |
15688 KB |
Output is correct |
46 |
Correct |
236 ms |
17988 KB |
Output is correct |
47 |
Correct |
224 ms |
18016 KB |
Output is correct |
48 |
Correct |
250 ms |
22876 KB |
Output is correct |
49 |
Correct |
244 ms |
23496 KB |
Output is correct |
50 |
Correct |
276 ms |
17104 KB |
Output is correct |
51 |
Correct |
225 ms |
18412 KB |
Output is correct |
52 |
Correct |
270 ms |
19340 KB |
Output is correct |
53 |
Correct |
169 ms |
15072 KB |
Output is correct |
54 |
Correct |
247 ms |
22844 KB |
Output is correct |
55 |
Correct |
251 ms |
22852 KB |
Output is correct |