Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> pi;
- typedef pair<ll, ll> pl;
- typedef vector<int> vi;
- typedef vector<ll> vl;
- typedef vector<double> vd;
- typedef vector<bool> vb;
- typedef vector<char> vc;
- typedef vector<string> vs;
- typedef vector<pi> vp;
- typedef vector<pl> vpl;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- cerr.tie(nullptr);
- int n, k;
- cin >> n >> k;
- vi a(n);
- for (auto& i : a)
- cin >> i;
- int res = INT32_MAX;
- for (int i = 0; i < n; ++i){
- int s = a[i], sol = 0;
- for (int j = i + 1; j < n; ++j){
- s += k;
- if (a[j] != s)
- ++sol;
- }
- s = a[i];
- for (int j = i - 1; j > -1; --j){
- s -= k;
- if (a[j] != s)
- ++sol;
- }
- res = min(sol, res);
- }
- cout << res << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement