제출 #1267817

#제출 시각아이디문제언어결과실행 시간메모리
1267817minhmc2019Rabbit Carrot (LMIO19_triusis)C++20
14 / 100
281 ms472 KiB
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    long long M;
    if(!(cin >> N >> M)) return 0;
    vector<long long> a(N);
    for(int i = 0; i < N; ++i) cin >> a[i];

    int best = 0;
    int lim = 1 << N;
    for(int mask = 0; mask < lim; ++mask){
        bool ok = true;
        int prev_idx = -1;        // trước đầu là "vị trí bắt đầu"
        long long prev_h = 0;     // height tại vị trí bắt đầu = 0
        int cnt = 0;
        for(int i = 0; i < N; ++i){
            if(mask & (1 << i)){
                long long steps = i - prev_idx; // nếu prev_idx=-1 thì steps = i+1
                long long maxAllowed = prev_h + steps * M;
                if(a[i] > maxAllowed){
                    ok = false;
                    break;
                }
                prev_idx = i;
                prev_h = a[i];
                ++cnt;
            }
        }
        if(ok) best = max(best, cnt);
    }

    cout << (N - best) << '\n';
    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...