제출 #385222

#제출 시각아이디문제언어결과실행 시간메모리
385222SansPapyrus683Rabbit Carrot (LMIO19_triusis)Java
100 / 100
344 ms23236 KiB
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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...