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. 关于java使用double还是float

    眼睛一亮在论坛上发现一枚很有价值的评论赶紧抄下来... 记住java一定要用double,更鼓不变,就算数值不大也要用double.了解java虚拟机的底层会知道,float放在内存中其实是当作dou ...

  2. 虚拟机下 rm -rf / 尝试

    环境:虚拟机 系统版本:centOS 5.8.centOS 6.5 1. root权限:rm -rf / 2. root权限:rm -rf /* 测试结果:5.8下执行命令1,2,根目录文件被删除,系 ...

  3. apache不解析php文件遍历目录

    程序目录下有index.php缺不能正常解析,直接刷出整个目录. 解决:在后面添加index.php的解析即可.. DirectoryIndex index.html index.html.var i ...

  4. 关于14道魔鬼js考题的整理

    1.(function(){ return typeof arguments })(); 这里返回时是argument类型,它是个类数组,也就对象,所以是object,准确谁是[object argu ...

  5. Daily Scrum 10

    今天我们小组开会内容分为以下部分: part 1: 经过反复思考,对于上次组会确定的在系统中加入娱乐版块进行了更进一步的商讨; part 2:继续探讨算法实现: part 3:进行明日的任务分配; ◆ ...

  6. [经典贪心算法]Prim算法

    最小生成树的Prim算法也是贪心算法的一大经典应用.Prim算法的特点是时刻维护一棵树,算法不断加边,加的过程始终是一棵树. Prim算法过程: 一条边一条边地加, 维护一棵树. 初始 E = {}空 ...

  7. LintCode-54.转换字符串到整数

    转换字符串到整数 实现atoi这个函数,将一个字符串转换为整数.如果没有合法的整数,返回0.如果整数超出了32位整数的范围,返回INT_MAX(2147483647)如果是正整数,或者INT_MIN( ...

  8. MFC消息处理

    1.MFC窗口如何与AfxWndProc建立联系. 当一个新的CWnd派生类创建时,在调用CWnd::CreateEx()过程中,MFC都会安装AfxCbtFilterHook().这个Hook将拦截 ...

  9. OSG学习:自动对齐节点示例

    /********************************************************** *Write by FlySky *zzuxp@163.com http://w ...

  10. alpha阶段个人总结(201521123031林庭亦)

    一.个人总结 第一部分:硬的问题 第二部分:软的问题,在成长路上学到了什么? 1 当你看到不靠谱的设计.糟糕的代码.过时的文档和测试用例的时候,不要想 "既然别人的代码已经这样了,我的代码也 ...