Submission #404586

#TimeUsernameProblemLanguageResultExecution timeMemory
404586TruaShamuRabbit Carrot (LMIO19_triusis)Java
100 / 100
320 ms23268 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 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...