제출 #481108

#제출 시각아이디문제언어결과실행 시간메모리
481108s_samchenkoRabbit Carrot (LMIO19_triusis)C++17
63 / 100
1088 ms3780 KiB
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define ll long long
#define ff first
#define ss second
#define int ll
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define pii pair <int, int>
using namespace std;
const int inf = 1e15;
const int mod = 1e9+7;
const int N = 3e5+100;

struct segtree{
	int size;
	vector <int> t;
	
	segtree(int n){
		size = 1;
		while (size < n) size <<= 1;
		t.resize(2*size - 1);
	}
	
	void set(int i, int v, int x, int lx, int rx){
		if (rx - lx == 1){
			t[x] = v;
			return;
		}
		int m = (lx + rx) / 2;
		if (i < m) set(i, v, 2*x + 1, lx, m);
		else set(i, v, 2*x + 2, m, rx);
		t[x] = max(t[2*x + 1], t[2*x + 2]);
	}
	
	void set(int i, int v){
		set(i, v, 0, 0, size);
	}
	
	int get(int l, int r, int x, int lx, int rx){
		if (l >= rx || lx >= r) return 0;
		if (l <= lx && r >= rx) return t[x];
		int m = (lx + rx) / 2;
		return max(get(l, r, 2*x + 1, lx, m), get(l, r, 2*x + 2, m, rx));
	}
	
	
	int get(int l, int r){
		return get(l, r + 1, 0, 0, size);
	}
};

void solve(){
	int n, m;
	cin >> n >> m;
	vector <int> a(n+1);
	for (int i = 1; i <= n; ++i) cin >> a[i];
	vector <int> dp(n+1);
	dp[0] = 0;
	for (int i = 1; i <= n; ++i){
		if (a[i] > m * i){
			dp[i] = -inf;
			continue;
		}
		dp[i] = 1;
		for (int j = i - 1; j > 0; --j){
			if (dp[j] == -inf) continue;
			if (a[j] + m * (i - j) >= a[i]) dp[i] = max(dp[i], dp[j] + 1);
		}
	}
	
	cout << n - *max_element(all(dp));
}

signed main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int tt = 1;
	//cin >> tt;
	while (tt--){
		solve();
		cout << '\n';
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...