303205: CF624B. Making a String

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Making a String

题意翻译

从26个字母中给你n个字母,你想用这些字母拼成一个尽可能长的字符串。并且这个字符串满足以下条件: 1、第i个字母最多可以在字符串中出现ai次; 2、每一个可以被使用至少一次的字母的使用次数都不能相等。 现在,这个字符串的长度是多少呢? 输入: 第一行:n(2<=n<=26) 第二行:n个数,表示ai; 输出: 一行,字符串的最长长度 感谢@____233____ 提供的翻译

题目描述

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.

输入输出格式

输入格式


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}<=10^{9} $ ) — $ i $ -th of these integers gives the limitation on the number of occurrences of the $ i $ -th character in the string.

输出格式


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".

Input

题意翻译

从26个字母中给你n个字母,你想用这些字母拼成一个尽可能长的字符串。并且这个字符串满足以下条件: 1、第i个字母最多可以在字符串中出现ai次; 2、每一个可以被使用至少一次的字母的使用次数都不能相等。 现在,这个字符串的长度是多少呢? 输入: 第一行:n(2<=n<=26) 第二行:n个数,表示ai; 输出: 一行,字符串的最长长度 感谢@____233____ 提供的翻译

加入题单

算法标签: