이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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... |