답안 #404584

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404584 2021-05-14T17:03:40 Z TruaShamu Rabbit Carrot (LMIO19_triusis) Java 11
0 / 100
89 ms 9256 KB
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;
        }
    }
}

# 결과 실행 시간 메모리 Grader output
1 Runtime error 89 ms 9256 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 89 ms 9256 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 89 ms 9256 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 89 ms 9256 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -