Submission #1266957

#TimeUsernameProblemLanguageResultExecution timeMemory
1266957dhuyyyyRabbit Carrot (LMIO19_triusis)C++20
100 / 100
31 ms5232 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;

using ll = long long;
using ii = pair<int,int>;
using pii = pair<int,ii>;
using aa = array<int,3>;

const int N = 2e5+5;
const int M = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n, t, x, s, res = 0, cnt = 0, a[N], BIT[N];

vector <int> v;

void update(int id,int val){
    while (id <= n){
        BIT[id] = max(BIT[id],val);
        id += id & -id;
    }
}
int get(int id){
    int res = 0;
    while (id){
        res = max(res,BIT[id]);
        id -= id & -id;
    }
    return res;
}
int calc(int val){
    return lower_bound(v.begin(),v.end(),val) - v.begin();
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n >> t;
    for (int i = 1; i <= n; i++){
        cin >> x;
        x = (t * i - x);
        if (x >= 0){
            v.push_back(x);
            a[++cnt] = x;
        }
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    for (int i = 1; i <= cnt; i++){
        a[i] = calc(a[i]) + 1;
    }
    for (int i = 1; i <= cnt; i++){
        int cur = get(a[i]) + 1;
        update(a[i],cur);
        res = max(res,cur);
    }
    cout << n - res;
    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...