/*
题意:问最少增加多少值使变成递增序列
贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >=
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; typedef long long ll; const int MAXN = 3e3 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN]; int main(void) //Codeforces Round #304 (Div. 2) B. Soldier and Badges
{
int n;
while (scanf ("%d", &n) == )
{
for (int i=; i<=n; ++i) scanf ("%d", &a[i]);
sort (a+, a++n); int tot = ; a[] = ;
for (int i=; i<=n; ++i)
{
if (a[i-] >= a[i]) {tot += (a[i-] - a[i] + ); a[i] = a[i-] + ;}
} printf ("%d\n", tot);
} return ;
} /*
4
1 3 1 4
5
1 2 3 2 5
4
4 3 2 2
*/
相关文章
- 04-06Codeforces Round #622 (Div. 2) B. Different Rules(数学)
- 04-06贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges
- 04-06Codeforces Round #517 (Div. 2) C. Cram Time(思维+贪心)
- 04-06Codeforces Round #703 (Div. 2)__ B. Eastern Exhibition__ 纯纯的思维
- 04-06Codeforces Round #576 (Div. 2) B. Water Lily
- 04-06Educational Codeforces Round 100 (Rated for Div. 2)B. Find The Array(构造)
- 04-06Codeforces Round #735 (Div. 2) B. Cobb
- 04-06Codeforces Round #369 (Div. 2) B. Chris and Magic Square 水题
- 04-06Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) E - Aquarium decoration 贪心 + 平衡树
- 04-06【分类讨论】【set】Codeforces Round #407 (Div. 2) B. Masha and geometric depression