Submission #750611

#TimeUsernameProblemLanguageResultExecution timeMemory
750611dmotRabbit Carrot (LMIO19_triusis)C++17
0 / 100
1 ms212 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...