category-wise-problems

contains category wise problems(data structures, competitive) of popular platforms.

View the Project on GitHub mayankdutta/category-wise-problems

C - Linear Approximation

Code implementation ```cpp int n; cin >> n; std ::vector arr(n); for (auto &i : arr) cin >> i; for (int i = 0; i < n; i++) arr[i] -= (i + 1); sort((arr).begin(), (arr).end()); int median = (n & 1 ? arr[n / 2] : arr[(n - 1) / 2]); ll ans = 0; for (const auto &i : arr) ans += (abs(i - median)); cout << ans << '\n'; ``` </details>