제출 #747580

#제출 시각아이디문제언어결과실행 시간메모리
747580vjudge1Rabbit Carrot (LMIO19_triusis)C++17
100 / 100
34 ms5380 KiB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define pb push_back
#define gcd __gcd
#define endl "\n"
#define task "hihi"
using namespace std;
const int N = 2e5 + 5, MOD = 1e9 + 7, INF = 1e18 + 5;  
int n, x, a[N], b[N];
int solve(){
    int res = 0;
    b[0] = -INF;
    for(int i = 1; i <= n; i++) b[i] = INF;
    for(int i = 1; i <= n; i++){
        if(a[i] > i * x) continue;
        int lo = 0, hi = n, ans = -1;
        while(lo <= hi){
            int mid = (lo + hi) / 2;
            if(b[mid] <= i * x - a[i]){
                lo = mid + 1, ans = mid;
            } else{
                hi = mid - 1;
            }
        }
        b[ans + 1] = min(i * x - a[i], b[ans + 1]);
        res = max(res, ans + 1);
    }
    return res;
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen(task".inp", "r", stdin);
    //freopen(task".out", "w", stdout);
    cin >> n >> x;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    cout << n - solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...