Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int MAX = (1e6)+1;
- int n, load, p[MAX];
- multiset<int> turn;
- long long res[MAX];
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(0);
- cin >> n;
- for(int i = 1; i <= n; i++) {
- cin >> p[i];
- if(p[i] < i) load--, turn.insert(i-p[i]);
- else load++;
- res[0] += abs(p[i] - i);
- }
- long long curr = res[0];
- for(int i = 1; i <= n; i++) {
- curr += load - p[i] + abs(p[i] - n);
- load -= 2;
- turn.insert(i+n-p[i]);
- res[i] = curr;
- while(!turn.empty() && *turn.begin() == i) {
- load += 2;
- turn.erase(turn.begin());
- }
- }
- int mn = 0;
- for(int i = 1; i <= n; i++) if(res[i] < res[mn]) mn = i;
- cout << res[mn] << ' ' << (n-mn)%n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement