Submission #400569

#TimeUsernameProblemLanguageResultExecution timeMemory
400569LatentGMRabbit Carrot (LMIO19_triusis)C++17
100 / 100
31 ms5312 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define endl        "\n"
#define pii         pair<int, int>
// #define int         long long 
#define ll              long long
#define fi          first
#define se          second
 
const int mod = (int)1e9 + 7;


void solve() {  
    
    int n, m; cin >> n >> m;
    int a[n];
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    vector<int> can; // candidate for height not change
    for(int i=0; i<n; i++) {
        if((i + 1)*m >= a[i]) {
            can.push_back((i + 1)*m - a[i]);
        }
    }
    // need to find the longest non-decreasing subsequence
    // for that many towers no height change is required
    vector<int> dp;
    for(int x : can)
    {
        int ub = upper_bound(dp.begin(), dp.end(), x) - dp.begin();
        if(ub == (int)dp.size()) dp.push_back(x);
        else dp[ub] = x;
    }
    int ans = n - (int)dp.size();
    cout << ans << endl;
}
 
signed main() {  
    
// #ifndef ONLINE_JUDGE    
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif  
 
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(15); 
 
    int T=1; 
    // cin >> T;
 
    for(int i=1; i<=T; i++) {
        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...