This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 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... |