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;
}

  

AIM Tech Round (Div. 2) B的更多相关文章

  1. AIM Tech Round (Div. 1) D. Birthday 数学 暴力

    D. Birthday 题目连接: http://www.codeforces.com/contest/623/problem/D Description A MIPT student named M ...

  2. AIM Tech Round (Div. 2) D. Array GCD dp

    D. Array GCD 题目连接: http://codeforces.com/contest/624/problem/D Description You are given array ai of ...

  3. AIM Tech Round (Div. 2) C. Graph and String 二分图染色

    C. Graph and String 题目连接: http://codeforces.com/contest/624/problem/C Description One day student Va ...

  4. AIM Tech Round (Div. 2) B. Making a String 贪心

    B. Making a String 题目连接: http://codeforces.com/contest/624/problem/B Description You are given an al ...

  5. AIM Tech Round (Div. 2) A. Save Luke 水题

    A. Save Luke 题目连接: http://codeforces.com/contest/624/problem/A Description Luke Skywalker got locked ...

  6. Codeforces AIM Tech Round (Div. 2)

    这是我第一次完整地参加codeforces的比赛! 成绩 news standings中第50. 我觉这个成绩不太好.我前半小时就过了前三题,但后面的两题不难,却乱搞了1.5h都没有什么结果,然后在等 ...

  7. AIM Tech Round (Div. 2) A

    A. Save Luke time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  8. AIM Tech Round (Div. 1) C. Electric Charges 二分

    C. Electric Charges 题目连接: http://www.codeforces.com/contest/623/problem/C Description Programmer Sas ...

  9. AIM Tech Round (Div. 2) C. Graph and String

    C. Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. Linux 文件的常识

    文件 文件的分类 文件 目录 链接 区分办法,ls -la 查看 十个标志符中的第一个 如:drwxrwxr-x. 2 normal normal 4096 8月 31 23:43 dir 目录是d ...

  2. 使用flask_limiter设定API配额

    前言 闲来无事,突然想到了以前做过的关于后台API安全方面的事,关于接口访问配额的设置,flask有没有很好的库支持呢?一找还真有!主要是对照了库的官方文档自己写了下dome,以供参考. # -*- ...

  3. Java中二进制数与整型之间的转换

    import java.io.*; public class Test{ /** * 二进制与整型之间的转换 * @param args * @throws IOException */ public ...

  4. 理解Python中的__builtin__和__builtins__

    以Python 2.7为例,__builtin__模块和__builtins__模块的作用在很多情况下是相同的. 但是,在Python 3+中,__builtin__模块被命名为builtins. 所 ...

  5. ServiceStack.Ormlit 事务

    应该使用这个方法开启事务 public static IDbTransaction OpenTransaction(this IDbConnection dbConn) { return new Or ...

  6. HADOOP docker(四):安装hive

    1.hive简介2.安装hive2.1 环境准备2.1.1 下载安装包2.1.2 设置hive用户的环境变量2.1.3 hive服务端配置文件2.1.4 hive客户端配置文件2.1.4 分发hive ...

  7. 如果Python对于磁盘没有写入权限,还会运行吗?

    Python如果对于磁盘没有写入权限,那么编译成功的字节码文件就只会存储在内存当中,而不会写入到磁盘,每次运行Python都会重新编译,然后运行.

  8. 软件工程 作业part3 读后感

    匆匆看完构建之法,觉得这种不认真看完书就去写随笔去评价这本书是对作者的不尊重,所以觉得应该提问题和写感悟. 我的一点拙见,提的问题在现在这个信息发达的时候感觉只要有时间都可以自己解决. 感觉软件工程这 ...

  9. PMS

    "通讯录--PMS"功能介绍及界面展示 首先是我们的登陆界面,以绿色为基调,配以繁星组成的星阵图,寓意为"散是满天星",希望每一位同学能在各自的生活中闪耀. 当 ...

  10. bootstrap列表添加滚动条

    有时候列表中数据过多,导致超出页面,影响视觉感受.这时我们需要添加一个滚动条. 初始状态如图: 代码如下: <ul class="list-group"> <li ...