B. Making a String
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ai 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.
Input

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 ai (1 ≤ ai ≤ 109) — i-th of these integers gives the limitation on the number of occurrences of the i-th character in the string.

Output

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

Sample test(s)
Input
3
2 5 5
Output
11
Input
3
1 1 2
Output
3
Note

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

题意:n种字母 每种字母分别最多出现ai次 要求 每种字母出现次数都不同

题解 a[]排序 当前字母最多出现次数未被占据 则 exm-- 累加

#include<bits/stdc++.h>
using namespace std;
#define LL __int64
int n;
int a[30];
map<int,int> mp;
int main()
{
scanf("%d",&n);
mp.clear();
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
LL ans=a[n-1];
mp[a[n-1]]=1;
for(int i=n-2;i>=0;i--)
{
int exm=a[i];
while(mp[exm]&&exm>0)
{
exm--;
}
ans+=exm;
mp[exm]=1;
}
printf("%I64d\n",ans);
return 0;
}

  

最新文章

  1. Oracle forall bulk collect批量数据更新
  2. 清华学堂 LightHouse
  3. MSP430单片机的两种SPI总线实现方式
  4. 第9章 用内核对象进行线程同步(4)_死锁(DeadLock)及其他
  5. ASP.NET获取请求的url信息汇总
  6. MyBatis查询传一个参数时报错:There is no getter for property named &#39;sleevetype&#39; in &#39;class java.lang.Integer
  7. ERDAS 2013与ArcGIS10.1安装时的兼容性问题
  8. IIS 7.5 配置Asp+Access的几点注意的地方
  9. Android模拟器中安装APK文件(转)
  10. 数据库之mysql 视图
  11. PowerDesigner一些小技巧
  12. MVC route 和 Angular router 单页面的一些方式
  13. iOS项目更新之升级Xcode7 &amp; iOS9
  14. SVN无法修改以前提交日志的办法
  15. 连载:面向对象葵花宝典:思想、技巧与实践(28) - 设计原则:内聚&amp;amp;耦合
  16. 安卓请求服务器js文件下载到本地,版本号就下载
  17. css 单行文本居中显示,多行文本左对齐
  18. JavaScript中常见的十五种设计模式
  19. ganglia使用nagios告警
  20. at MySql.Data.MySqlClient.MySqlStream.ReadPacket 或 FUNCTION account.AddMinutes does not exist

热门文章

  1. 解决ssh_exchange_identification:read connection reset by peer 原因
  2. 1.安装hbase
  3. 【转载】java byte转十六进制
  4. nodejs笔记--与Redis的交互篇(六)
  5. 条款02:尽量以const,enum,inline替换#define
  6. Deeplearning——Logistics回归
  7. LintCode-373.奇偶分割数组
  8. Swift-元祖
  9. IOS开发NSBundle使用
  10. fcntl函数详解