Submission #851249

#TimeUsernameProblemLanguageResultExecution timeMemory
851249overwatch9Rabbit Carrot (LMIO19_triusis)C++17
100 / 100
69 ms5024 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n, m; cin >> n >> m; vector <int> nums(n+1); for (int i = 1; i <= n; i++) cin >> nums[i]; vector <int> b(n+1); // refer to usaco editorial for this for (int i = 1; i <= n; i++) { if (m * i - nums[i] >= 0) b[i] = m * i - nums[i]; else b[i] = -1; } // find longest non decreasing subsequence vector <int> dp; for (int i = 1; i <= n; i++) { if (b[i] == -1) continue; auto x = upper_bound(dp.begin(), dp.end(), b[i]); if (x == dp.end()) dp.push_back(b[i]); else *x = b[i]; } cout << n - dp.size() << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...