This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.ArrayList;
public class triusis {
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());
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) {
int pos = bisectRight(minEndings, i);
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;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |