This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std ;
using ll = long long ;
int32_t main() {
ios::sync_with_stdio(false) ;
cin.tie(nullptr) ;
int n , m ; cin >> n >> m ;
vector<ll> a(n) ;
for (ll &i : a) cin >> i ;
vector<ll> b ;
for (int i = 0 ; i < n ; i++) {
ll cur = (i + 1) * m - a[i] ;
if (cur >= 0) {
b.push_back(cur) ;
}
}
auto calc = [&](vector<ll>& v) -> int {
multiset<pair<ll,ll>> s;
for (ll i : v) {
if (!s.size()) {
s.insert({i, 1}) ;
continue ;
}
auto it = s.upper_bound({i, i}) ;
if (it == s.begin()) {
s.insert({i, 1}) ;
} else { it-- ;
auto [value, dp] = *it ;
s.erase(it) ;
s.insert({i, dp + 1}) ;
}
}
ll mx = 0 ;
for (auto [v, dp] : s) {
mx = max(mx ,dp) ;
}
return mx ;
};
// cout << calc(b) << "\n" ;
cout << n - calc(b) ;
return 0 ;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |