Submission #1172990

#TimeUsernameProblemLanguageResultExecution timeMemory
1172990bebebebeRabbit Carrot (LMIO19_triusis)C++20
100 / 100
49 ms2240 KiB
//
// Created by Bryant Yu on 3/23/25.
//
#include <iostream>
#include <climits>
#include <iterator>
#include <vector>

using namespace std;

int main() {
    int n,m;
    cin >> n >> m;
    int arr[n+1];
    arr[0] = 0;
    for (int i=1;i<=n; i++) {
        int a;
        cin >> a;
        a -= i * m;
        arr[i]=-a;
    }
    //jump height max 0
    //since changing height of pillars does not change jump height (pillar change all happens before move)
    //this means path is nonincreasing
    //find longest decreasing path , i.e. longest nonincreasing subarray
    //dp[length] = value of the smallest end number of a nonincreasing subarray with legnth length.
    vector<int> dp;
    for (int i : arr) {
        int pos = upper_bound(dp.begin(), dp.end(), i) - dp.begin();
        if (pos == dp.size()) {
            // we can have a new, longer increasing subsequence!
            dp.push_back(i);
        } else {
            // oh ok, at least we can make the ending element smaller
            if (pos != 0) {
                dp[pos] = i;
            }
        }
    }
    int ans = n+1-dp.size();
    cout<<ans;
    //add 1 to ans if 0 isn't part of the sequence






}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...