이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
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 br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
ArrayList<Integer> unch = new ArrayList<>();
for (int i = 0; i < N; i++) {
int x = Integer.parseInt(br.readLine());
if ((i + 1) * M >= x) {
unch.add((i + 1) * M - x);
}
}
System.out.println(N - NDS(unch));
}
private static int NDS(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;
}
}
/*
5 400
300
700
200
1000
500
*/
# | 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... |