Submission #549915

#TimeUsernameProblemLanguageResultExecution timeMemory
549915AlexandruabcdeRabbit Carrot (LMIO19_triusis)C++14
100 / 100
37 ms5288 KiB
#include <bits/stdc++.h> using namespace std; typedef long long LL; constexpr int NMAX = 2e5 + 5; int N, M; LL A[NMAX]; /* j < i j -> i A[j] >= A[i] */ void Read () { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> M; for (int i = 1; i <= N; ++ i ) { cin >> A[i]; A[i] -= (1LL * i * M); } } int vf; LL Best[NMAX]; int CautBinar (LL value) { int st = 1, dr = vf; int ans = 0; while (st <= dr) { int mij = (st + dr) / 2; if (Best[mij] <= value) { st = mij + 1; ans = mij; } else dr = mij - 1; } return ans; } void Solve () { for (int i = N; i >= 1; -- i ) { int pos = CautBinar(A[i]) + 1; if (pos > vf) { ++ vf; Best[vf] = A[i]; } Best[pos] = min(Best[pos], A[i]); } cout << N - CautBinar(0) << '\n'; } int main () { Read(); Solve(); 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...