제출 #763139

#제출 시각아이디문제언어결과실행 시간메모리
763139phongcdRabbit Carrot (LMIO19_triusis)C++14
100 / 100
41 ms4032 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long  double
#define ull unsigned long long
#define ii pair <int, int>
#define ill pair <ll, ll>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define file "test"
using namespace std;
const int N = 2e5 + 2;
const ll MOD = 998244353;
const ll INF = 1e18;
const int base = 311;
const int BLOCK_SIZE = 2000;

int n, h;
int a[N], bit[N];
vector <int> b;

void upd(int idx, int v) {
    for (; idx <= n; idx += idx & -idx)
        bit[idx] = max(bit[idx], v);
}

int get(int idx) {
    int ans = 0;
    for (; idx > 0; idx -= idx & -idx)
        ans = max(ans, bit[idx]);
    return ans;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);


	cin >> n >> h;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i], a[i] = h * i - a[i];
        if (a[i] >= 0) b.push_back(a[i]);
    }
 
    sort(all(b));
    b.erase(unique(all(b)), b.end());
    for (int i = 1; i <= n; i ++) if (a[i] >= 0)
        a[i] = lower_bound(all(b), a[i]) - b.begin() + 1;
 
    int ans = 0;
    for (int i = 1; i <= n; i ++) if (a[i] >= 0) {
        int res = get(a[i]) + 1;
        ans = max(ans, res);
        upd(a[i], res);    
    }
    cout << n - ans;
}
/*
     /\_/\ zzZ
    (= -_-)
    / >u  >u
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...