Advertisement
Guest User

Artihmetic progression

a guest
Jun 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> pi;
  7. typedef pair<ll, ll> pl;
  8. typedef vector<int> vi;
  9. typedef vector<ll> vl;
  10. typedef vector<double> vd;
  11. typedef vector<bool> vb;
  12. typedef vector<char> vc;
  13. typedef vector<string> vs;
  14. typedef vector<pi> vp;
  15. typedef vector<pl> vpl;
  16.  
  17. int main()
  18. {
  19.     ios_base::sync_with_stdio(false);
  20.     cin.tie(nullptr);
  21.     cout.tie(nullptr);
  22.     cerr.tie(nullptr); 
  23.  
  24.     int n, k;
  25.     cin >> n >> k;
  26.  
  27.     vi a(n);
  28.     for (auto& i : a)
  29.         cin >> i;
  30.  
  31.     int res = INT32_MAX;
  32.     for (int i = 0; i < n; ++i){
  33.         int s = a[i], sol = 0;
  34.         for (int j = i + 1; j < n; ++j){
  35.             s += k;
  36.             if (a[j] != s)
  37.                 ++sol;
  38.         }
  39.         s = a[i];
  40.         for (int j = i - 1; j > -1; --j){
  41.             s -= k;
  42.             if (a[j] != s)
  43.                 ++sol;
  44.         }
  45.         res = min(sol, res);
  46.     }
  47.  
  48.     cout << res << '\n';
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement