/* -*- coding: utf-8 -*- * * 2029.cc: No.2029 Swap Min Max Min - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 200000; const long long LINF = 1LL << 62; /* typedef */ typedef long long ll; /* global variables */ int as[MAX_N], fs[MAX_N][2]; ll dp[MAX_N + 1][2]; /* subroutines */ inline void setmin(ll &a, ll b) { if (a > b) a = b; } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i); int x = n / 2; for (int i = 0, j = 0, k = 0; i < n; i++) { if (as[i] > x) j++; else { fs[k][0] = abs(j - k), fs[k][1] = abs(j - 1 - k); k++; } } //for (int i = 0; i < x; i++) printf("%d,%d ", fs[i][0], fs[i][1]); //putchar('\n'); if (n & 1) { ll y = 0; for (int i = 0; i < x; i++) y += fs[i][1]; printf("%d %lld\n", x, y); } else { for (int i = 0; i <= x; i++) dp[i][0] = dp[i][1] = LINF; dp[0][0] = dp[0][1] = 0; for (int i = 0; i < x; i++) { setmin(dp[i + 1][0], min(dp[i][0], dp[i][1]) + fs[i][0]); setmin(dp[i + 1][1], dp[i][1] + fs[i][1]); } ll y = min(dp[x][0], dp[x][1]); printf("%d %lld\n", x, y); } return 0; }