이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n; cin >> n;
ll m; cin >> m;
vector<ll> a(n+1);
for (int i = 1; i <= n; ++i) cin >> a[i];
vector<ll> dp(n+1, -1e7);
dp[0] = 0;
vector<pair<ll, int>> st;
st.push_back({0, 0});
for (int i = 1; i <= n; ++i) {
while (st.size() && ((st.front().first + m * (i - st.front().second)) < a[i])) {
st.pop_back();
}
if (!st.size()) {
// need to change all of them
// cerr << "i : " << i << endl;
dp[i] = i;
st.push_back({m * i, i});
} else {
dp[i] = 1 + dp[st.front().second];
st.push_back({a[i], i});
}
}
cout << dp[n] << endl;
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... |