Submission #1040670

#TimeUsernameProblemLanguageResultExecution timeMemory
1040670lmaobruhRabbit Carrot (LMIO19_triusis)C++14
100 / 100
37 ms10696 KiB
// 027 072 207 270 702 720 #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define all(x) x.begin(), x.end() #define fo(i, a, b) for (int i = (a), b_ = (b); i <= b_; ++i) #define fod(i, a, b) for (int i = (a), b_ = (b); i >= b_; --i) #define rep(i, n) fo(i, 1, n) #define per(i, n) fod(i, n, 1) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) const int N = 1e6+5; int n, m, a[N], f[N]; bool reach[N]; ll b[N]; void upd(int p, int v) { for (; p; p -= p & -p) chmax(f[p], v); } int get(int p) { int tot = 0; for (; p <= n; p += p & -p) chmax(tot, f[p]); return tot; } void sol() { cin >> n >> m; reach[0] = 1; vector<ll> z; rep(i, n) { cin >> a[i]; b[i] = a[i] - m * i; z.pb(b[i]); } sort(all(z)); z.resize(unique(all(z))-z.begin()); int ans = 0; rep(i, n) if (b[i] <= 0) { b[i] = upper_bound(all(z), b[i])-z.begin(); int lns = get(b[i]) + 1; ans = max(ans, lns); upd(b[i], lns); } cout << n - ans; } signed main() { cin.tie(0) -> sync_with_stdio(0); // if (fopen("A.inp", "r")) freopen("A.inp", "r", stdin); int tc = 1, test = 0; // cin >> tc; while (++test <= tc) sol(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...