Submission #797099

#TimeUsernameProblemLanguageResultExecution timeMemory
797099devariaotaRabbit Carrot (LMIO19_triusis)C++17
0 / 100
0 ms212 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; const ll MAXN = 2e5 + 5; const ll MAX = 1e18; ll n, m, ans = MAX, arr[MAXN]; void recur(ll idx, bool ubah, ll count, pll bef) { pll now = {max(0ll, bef.first-m), bef.second+m}; if (arr[idx] < now.first || arr[idx] > now.second) { if (!ubah) { return ; } } if (ubah) { count++; } if (idx == n) { ans = min(count, ans); return ; } recur(idx+1, true, count, now); recur(idx+1, false, count, now); return ; } int main(){ cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> arr[i]; } recur(1, true, 0, {0, 0}); cout << ans << "\n"; 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...