zoukankan      html  css  js  c++  java
  • Soldier and Badges CodeForces

    Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin.

    For every pair of soldiers one of them should get a badge with strictly higher factor than the second one. Exact values of their factors aren't important, they just need to have distinct factors.

    Colonel knows, which soldier is supposed to get which badge initially, but there is a problem. Some of badges may have the same factor of coolness. Help him and calculate how much money has to be paid for making all badges have different factors of coolness.

    Input

    First line of input consists of one integer n (1 ≤ n ≤ 3000).

    Next line consists of n integers ai (1 ≤ ai ≤ n), which stand for coolness factor of each badge.

    Output

    Output single integer — minimum amount of coins the colonel has to pay.

    Example

    Input
    4
    1 3 1 4
    Output
    1
    Input
    5
    1 2 3 2 5
    Output
    2

    Note

    In first sample test we can increase factor of first badge by 1.

    In second sample test we can increase factors of the second and the third badge by 1.

    变不一样  遇到一样的  让指针加一

     1 #include <iostream>
     2 
     3 using namespace std;
     4 #include<stack>
     5 #include<stdio.h>
     6 #include<math.h>
     7 #include<string.h>
     8 #include<map>
     9 #include<queue>
    10 #include<algorithm>
    11 int main()
    12 {
    13     int n,a[6010],i;
    14     while(cin>>n)
    15     {
    16         for(i=0;i<n;i++)
    17             cin>>a[i];
    18         int temp=0;
    19         sort(a,a+n);
    20         int sum=0;
    21         for(i=0;i<n;i++)
    22         {
    23                 if(a[i]>temp)
    24                     {
    25                         temp=a[i];
    26                     }
    27                 else
    28                 {
    29                     sum+=++temp-a[i];
    30                 }
    31         }
    32         cout<<sum<<endl;
    33     }
    34     return 0;
    35 }
    View Code
  • 相关阅读:
    Linux图形界面从登录列表中隐藏用户和开机自动登录
    VMware Workstation报错 : 另一个正在运行的VMware进程可能正在使用配置文件
    Vim命令总结
    Linux常用命令总结
    Oracle使用中的常规操作总结
    Oracle分页查询和SQL server分页查询总结
    Oracle学习总结
    Resharper2019 1.2破解教程
    C#实现RSA加密解密
    windows上git clone命令速度过慢问题的解决
  • 原文地址:https://www.cnblogs.com/dulute/p/7272554.html
Copyright © 2011-2022 走看看