DuongNhi99

SEQGAME (DDBB 2019)

Mar 23rd, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1005;
  5. const int64_t INF = 1e18;
  6.  
  7. int n, d;
  8. vector<int> a;
  9.  
  10. int64_t solve() {
  11.     int64_t ans = INF;
  12.     for(int i = 0; i < n; ++i) {
  13.         int64_t diff = 0;
  14.         for(int j = 0; j < n; ++j)
  15.             diff += abs((j - i) * d + a[i] - a[j]);
  16.         ans = min(ans, diff);
  17.     }
  18.  
  19.     return ans;
  20. }
  21.  
  22. int main() {
  23. #ifdef LOCAL
  24.     freopen("in.txt", "r", stdin);
  25. #else
  26.     freopen("SEQGAME.inp", "r", stdin);
  27.     freopen("SEQGAME.out", "w", stdout);
  28. #endif
  29.     ios_base::sync_with_stdio(false);
  30.     cin.tie(NULL); cout.tie(NULL);
  31.  
  32.     cin >> n >> d;
  33.     for(int i = 1; i <= n; ++i) {
  34.         int x; cin >> x;
  35.         a.push_back(x);
  36.     }
  37.  
  38.     cout << solve();
  39.  
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment