이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class glo {
public static void main(String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer initial = new StringTokenizer(read.readLine());
int tempNum = Integer.parseInt(initial.nextToken());
int maxCheating = Integer.parseInt(initial.nextToken());
int[] temps = Arrays.stream(read.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
int[] prefLongest = new int[tempNum];
ArrayList<Integer> minEndings = new ArrayList<>();
for (int i = 0; i < tempNum; i++) {
int t = temps[i];
int pos = bisectLeft(minEndings, t);
prefLongest[i] = pos + 1;
if (pos == minEndings.size()) {
minEndings.add(t);
} else {
minEndings.set(pos, t);
}
}
int longest = 0;
ArrayList<Integer> maxBegins = new ArrayList<>();
for (int i = tempNum - 1; i >= 0; i--) {
int t = temps[i];
int pos = bisectLeft(maxBegins, -t);
longest = Math.max(longest, prefLongest[i] + pos);
int insertPos = bisectLeft(maxBegins, -t - maxCheating);
if (insertPos == maxBegins.size()) {
maxBegins.add(-t - maxCheating);
} else {
maxBegins.set(insertPos, -t - maxCheating);
}
}
System.out.println(longest);
}
private static int bisectLeft(List<Integer> arr, int x) {
int lo = 0;
int hi = arr.size();
while (lo < hi) {
int mid = (lo + hi) / 2;
if (arr.get(mid) < x) {
lo = mid + 1;
} else {
hi = mid;
}
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |