Submission #404584

#TimeUsernameProblemLanguageResultExecution timeMemory
404584TruaShamuRabbit Carrot (LMIO19_triusis)Java
0 / 100
89 ms9256 KiB
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 st = new StringTokenizer(read.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(read.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 = upper_bound(minEndings, i); if (pos == minEndings.size()) { minEndings.add(i); } else { minEndings.set(pos, i); } } return minEndings.size(); } public static int upper_bound(ArrayList<Integer> arr, int key) { int len = arr.size(); int lo = 0; int hi = len-1; int mid = (lo + hi)/2; while (true) { int cmp = arr.get(mid).compareTo( key); if (cmp == 0 || cmp < 0) { lo = mid+1; if (hi < lo) return mid<len-1?mid+1:-1; } else { hi = mid-1; if (hi < lo) return mid; } mid = (lo + hi)/2; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...