Advertisement
halexandru11

Untitled

Dec 7th, 2021
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. #include <algorithm>
  2. #include <array>
  3. #include <bitset>
  4. #include <cassert>
  5. #include <climits>
  6. #include <cmath>
  7. #include <complex>
  8. #include <cstdio>
  9. #include <cstdlib>
  10. #include <cstring>
  11. #include <fstream>
  12. #include <functional>
  13. #include <iomanip>
  14. #include <iostream>
  15. #include <map>
  16. #include <memory>
  17. #include <numeric>
  18. #include <queue>
  19. #include <random>
  20. #include <set>
  21. #include <stack>
  22. #include <string>
  23. #include <unordered_set>
  24. #include <unordered_map>
  25. #include <vector>
  26. using namespace std;
  27.  
  28. /// START Errichto's debug
  29. #define sim template < class c
  30. #define ris return * this
  31. #define dor > debug & operator <<
  32. #define eni(x) sim > typename \
  33. enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
  34. sim > struct rge { c b, e; };
  35. sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
  36. sim > auto dud(c* x) -> decltype(cerr << *x, 0);
  37. sim > char dud(...);
  38. struct debug {
  39. #ifdef LOCAL
  40. ~debug() { cerr << endl; }
  41. eni(!=) cerr << boolalpha << i; ris; }
  42. eni(==) ris << range(begin(i), end(i)); }
  43. sim, class b dor(pair < b, c > d) {
  44. ris << "(" << d.first << ", " << d.second << ")";
  45. }
  46. sim dor(rge<c> d) {
  47. *this << "[";
  48. for (auto it = d.b; it != d.e; ++it)
  49. *this << ", " + 2 * (it == d.b) << *it;
  50. ris << "]";
  51. }
  52. #else
  53. sim dor(const c&) { ris; }
  54. #endif
  55. };
  56. #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
  57. // debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
  58. /// END Errichto's debug
  59.  
  60. #define ff first
  61. #define ss second
  62. #define eb emplace_back
  63. #define mp make_pair
  64. #define pb push_back
  65. #define ppb pop_back
  66. #define all(a) a.begin(), a.end()
  67. #define rall(a) a.rbegin(), a.rend()
  68. #define f0(i, n) for(int i = 0; i < n; ++i)
  69. #define fo(i, k, n) for(int i = k; i < n; ++i)
  70. #define foo(i, a, b, k) for(int i = a; i < b; i += k)
  71. #define rf0(n, i) for(int i = n-1; ~i; --i)
  72. #define rfo(n, k, i) for(int i = n-1; i >= k; --i)
  73. #define rfoo(b, a, k, i) for(int i = b; i > a; i -= k)
  74. #define Im_speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
  75.  
  76. typedef long double ld;
  77. typedef uint32_t uint;
  78. typedef int64_t ll;
  79. typedef uint64_t ull;
  80.  
  81. //ifstream fin("date.in");
  82. //ofstream fout("date.out");
  83.  
  84. const int nax = 1e5 + 3;
  85. const int mod = 1e9 + 7;
  86. const int inf = 1e9 + 7;
  87. const ll infll = 1e18 + 7;
  88. const ld PI = 3.1415926535897932384626433832795;
  89.  
  90. void test_case() {
  91. int n;
  92. cin >> n;
  93. vector<ll> a(n);
  94. ll sum = 0;
  95. ll neg = 0;
  96. f0(i, n) {
  97. cin >> a[i];
  98. a[i] -= (i+1);
  99. }
  100. sort(all(a));
  101.  
  102. int low = max(0, n/2 - 1);
  103. int high = min(n-1, n/2 + 1);
  104.  
  105. ll ans = infll;
  106. for(int i = low; i <= high; ++i) {
  107. ll b = a[i];
  108. ll sum = 0;
  109. f0(i, n) {
  110. sum += abs(a[i] - b);
  111. }
  112. ans = min(ans, sum);
  113. }
  114. cout << ans;
  115. }
  116.  
  117. int main() {
  118. // clock_t _clock = clock();
  119. Im_speed;
  120. cout << fixed << setprecision(12);
  121.  
  122. int t = 1;
  123. // cin >> t;
  124. while(t--) {
  125. test_case();
  126. }
  127.  
  128. // cout << "\n\nTime: " << ((((double) clock()) - ((double)_clock)) / ((double) CLK_TCK));
  129. }
  130.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement