CF351E.Jeff and Permutation

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence _p_1, _p_2, ..., p__n for his birthday.

Jeff hates inversions in sequences. An inversion in sequence _a_1, _a_2, ..., a__n is a pair of indexes i, j (1 ≤ i < j ≤ n), such that an inequality a__i > a__j holds.

Jeff can multiply some numbers of the sequence p by -1. At that, he wants the number of inversions in the sequence to be minimum. Help Jeff and find the minimum number of inversions he manages to get.

杰夫的朋友们非常清楚,这个男孩喜欢在生日时收到序列和数组。因此,杰夫生日收到了序列 p1, p2, …, pnp_1,\ p_2,\ \dots,\ p_n。

杰夫讨厌序列中的逆序对。在序列 a1, a2, …, ana_1,\ a_2,\ \dots,\ a_n 中,一个逆序对是指一对下标 (i, j)(i,\ j)(满足 1≤i<j≤n1 \le i < j \le n),使得不等式 ai>aja_i > a_j 成立。

杰夫可以将序列 pp 中的某些数乘以 −1-1。他希望经过操作后,序列中的逆序对数量尽可能少。请帮助杰夫,求出他所能达到的最小逆序对数量。

输入格式

The first line contains integer n (1 ≤ n ≤ 2000). The next line contains n integers — sequence _p_1, _p_2, ..., p__n (|p__i| ≤ 105). The numbers are separated by spaces.

第一行包含一个整数 nn(1≤n≤20001 \leq n \leq 2000)。下一行包含 nn 个整数——序列 p1,p2,…,pnp_1, p_2, \dots, p_n(∣pi∣≤105|p_i| \leq 10^5)。数字之间用空格分隔。

输出格式

In a single line print the answer to the problem — the minimum number of inversions Jeff can get.

在一行中输出问题的答案——Jeff 能得到的最少逆序对数量。

输入输出样例

  • 输入#1

    2
    2 1

    输出#1

    0
  • 输入#2

    9
    -2 0 -1 0 -1 2 1 0 -1

    输出#2

    6

输入解题思路,AI测评打分。不知道怎么写?

首页