Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1005;
- const int64_t INF = 1e18;
- int n, d;
- vector<int> a;
- int64_t solve() {
- int64_t ans = INF;
- for(int i = 0; i < n; ++i) {
- int64_t diff = 0;
- for(int j = 0; j < n; ++j)
- diff += abs((j - i) * d + a[i] - a[j]);
- ans = min(ans, diff);
- }
- return ans;
- }
- int main() {
- #ifdef LOCAL
- freopen("in.txt", "r", stdin);
- #else
- freopen("SEQGAME.inp", "r", stdin);
- freopen("SEQGAME.out", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(NULL); cout.tie(NULL);
- cin >> n >> d;
- for(int i = 1; i <= n; ++i) {
- int x; cin >> x;
- a.push_back(x);
- }
- cout << solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment