Submission #117505

#TimeUsernameProblemLanguageResultExecution timeMemory
117505FutymyCloneKrov (COCI17_krov)C++14
0 / 140
19 ms1784 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, a[N]; long long check (int mid) { long long sum = 0; int Min = 2e9 + 2277; for (int i = 1; i <= n; i++) { int need = a[mid] - abs(i - mid); sum += abs(need - a[i]); Min = min(Min, need); } if (Min <= 0) { sum = 0; for (int i = 1; i <= n; i++) { int need = a[mid] + 1 - Min - abs(i - mid); sum += abs(need - a[i]); } } return sum; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; //for (int i = 1; i <= n; i++) cout << check(i) << " "; //return 0; int l = 1, r = n; while (l <= r) { int mid = (l + r) >> 1; if (check(mid) < check(mid + 1)) r = mid - 1; else l = mid + 1; } cout << check(l); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...