DP预处理+枚举逆序对
/**
* Created by ckboss on 14-9-4.
*/
import java.util.*;
public class InsertionSort {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] a = new int[n + 10];
int[][] dp = new int[n + 10][n + 10];
for (int i = 1; i <= n; i++) {
a[i] = in.nextInt();
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < n; j++) {
int t = 0;
if (a[i] < j) t = 1;
dp[i][j] = dp[i - 1][j] + t;
}
}
int ISN = 0;
for (int i = 1; i <= n; i++)
ISN += i - 1 - dp[i][a[i]];
int MinISN = (1 << 30);
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (a[i] > a[j]) {
int len = j - i - 1;
int p = dp[j - 1][a[i]] - dp[i][a[i]];
int q = dp[j - 1][a[j]] - dp[i][a[j]];
int temp = ISN + 2 * (q - p) - 1;
if (temp < MinISN)
MinISN = temp;
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (a[i] > a[j]) {
int len = j - i - 1;
int p = dp[j - 1][a[i]] - dp[i][a[i]];
int q = dp[j - 1][a[j]] - dp[i][a[j]];
int temp = ISN + 2 * (q - p) - 1;
if (temp == MinISN)
ans++;
}
}
}
System.out.println(MinISN + " " + ans);
}
}