CF63B.Settlers' Training

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.

Every soldier has a rank — some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.

To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.

At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.

You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k.

在策略类电脑游戏《殖民者II》(Settlers II)中,玩家需建造防御建筑以拓展并保护自己的领地。我们来考察其中一种防御建筑:当前该防御建筑中恰好驻扎着 nn 名士兵。在本题中,我们可以假设该防御建筑中的士兵总数既不会增加也不会减少。

每名士兵都有一个军衔——即从 11 到 kk 的某个正整数。其中,11 代表列兵,kk 代表将军。士兵的军衔越高,其战斗力越强。因此,玩家希望尽可能让所有士兵达到最高的军衔。

为提升士兵的军衔,需要进行训练。但士兵不会免费训练,每次训练需消耗一枚金币。每次训练时,全部 nn 名士兵均参与。

每次训练结束后,士兵的军衔按如下规则提升:首先,将所有士兵按当前军衔分组,使得组数最少(即相同军衔的士兵被分入同一组);然后,在每一个包含军衔低于 kk 的士兵的组内,恰好有一名士兵将其军衔提升一级。

已知当前 nn 名士兵各自的军衔。请计算:为使所有士兵的军衔均提升至 kk,所需的最少金币数量。

输入格式

The first line contains two integers n and k (1 ≤ n, k ≤ 100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, a__i, represents the rank of the i-th soldier in the defense building (1 ≤ i ≤ n, 1 ≤ a__i ≤ k).

第一行包含两个整数 nn 和 kk(1≤n,k≤1001 \leq n, k \leq 100),分别表示士兵人数和不同军衔的种类数。
第二行包含 nn 个按非递减顺序排列的整数。其中第 ii 个数 aia_i 表示防御工事中第 ii 位士兵的军衔(1≤i≤n1 \leq i \leq n,1≤ai≤k1 \leq a_i \leq k)。

输出格式

Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank.

输出一个整数——将所有士兵提升至最高等级所需的金币数量。

输入输出样例

  • 输入#1

    4 4
    1 2 2 3

    输出#1

    4
  • 输入#2

    4 3
    1 1 1 1

    输出#2

    5

说明/提示

In the first example the ranks will be raised in the following manner:

1 2 2 3  →  2 2 3 4  →  2 3 4 4  →  3 4 4 4  →  4 4 4 4

Thus totals to 4 training sessions that require 4 golden coins.

在第一个例子中,等级将按如下方式提升:

1 2 2 3  →  2 2 3 4  →  2 3 4 4  →  3 4 4 4  →  4 4 4 4

因此总共需要 4 次训练课程,消耗 4 枚金币。

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

首页