Submission #1147373

#TimeUsernameProblemLanguageResultExecution timeMemory
1147373nitesh007Rabbit Carrot (LMIO19_triusis)C++17
100 / 100
16 ms3152 KiB
#include "bits/stdc++.h"
using namespace std;

#define ll long long

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

// Check Functions
bool isPrime(ll n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;
}
bool isPowerOfTwo(int n) {
    if (n == 0) return false;
    return (ceil(log2(n)) == floor(log2(n)));
}
bool isPerfectSquare(ll x) {
    if (x >= 0) {
        ll sr = sqrt(x);
        return (sr * sr == x);
    }
    return false;
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> heights(n), b(n);
    
    for (int i = 0; i < n; i++) {
        cin >> heights[i];
        b[i] = m * (i + 1) - heights[i]; // Transform heights to b[i]
    }

    vector<int> lanes; // Stores the LNDS sequence
    for (int i = 0; i < n; i++) {
        if (b[i] < 0) continue; // Only consider valid values
        auto it = upper_bound(lanes.begin(), lanes.end(), b[i]);
        if (it == lanes.end()) {
            lanes.push_back(b[i]);
        } else {
            *it = b[i];
        }
    }

    cout << (n - lanes.size()) << endl; // Minimum modifications needed
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int t = 1;
    //cin >> t;
    while (t--) {
        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...