CF624B.Making a String

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:

  • the i-th letter occurs in the string no more than a__i times;
  • the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once.

给你一个由 nn 个字母组成的字母表,你的任务是构造一个尽可能长的字符串,使得以下条件均满足:

  • 第 ii 个字母在字符串中出现的次数不超过 aia_i 次;
  • 字符串中每个至少出现一次的字母的出现次数必须互不相同。

输入格式

The first line of the input contains a single integer n (2  ≤  n  ≤  26) — the number of letters in the alphabet.

The next line contains n integers a__i (1 ≤ a__i ≤ 109) — i-th of these integers gives the limitation on the number of occurrences of the i-th character in the string.

输入的第一行包含一个整数 nn(2≤n≤262 \leq n \leq 26)—— 表示字母表中的字母个数。

接下来的一行包含 nn 个整数 aia_i(1≤ai≤1091 \leq a_i \leq 10^9)—— 其中第 ii 个整数表示字符串中第 ii 个字符的出现次数限制。

输出格式

Print a single integer — the maximum length of the string that meets all the requirements.

输出一个整数——满足所有要求的字符串的最大长度。

输入输出样例

  • 输入#1

    3
    2 5 5

    输出#1

    11
  • 输入#2

    3
    1 1 2

    输出#2

    3

说明/提示

For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc".

为方便起见,我们考虑一个由三个字母组成的字母表:“a”、“b”、“c”。在第一个样例中,一些最优字符串包括:“cccaabbccbb”、“aabcbcbcbcb”。在第二个样例中,一些最优字符串包括:“acc”、“cbc”。

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

首页