AIM Tech Round (Div. 2) B
2016-02-08 18:10
369 查看
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
Output
Input
Output
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-- 累加
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) A
- HDU-1023 Train Problem II 出栈序列问题
- hdu1789 Doing Homework again(贪心)
- HDU 1022 Train Problem I
- USACO--Barn Pepair
- LightOJ 1028 1028 - Trailing Zeroes (I) (求因子个数)
- Failed to load native-hadoop本地库不一致的解决办法
- NetworkOnMainThreadException
- Vim简明教程【CoolShell】转自http://blog.csdn.net/niushuai666/article/details/7275406 (飘过的小牛)
- JetBrains Cracker
- tortoisegit 常见错误disconnected no supported authentication methods available(server sent: publickey)
- aircrack-ng套装破解wifi过程详解
- color-scheme,颜色方案,jetbrains主题,webstrom
- 人工智能之一:什么是人工智能?
- #AIM Tech Round [div2] C. Graph and String 【连通图、染色】
- 使用Behavior Designer插件简单制作NPC AI
- Codeforces AIM Tech Round (Div. 2) 624A A. Save Luke
- Codeforces AIM Tech Round (Div. 2) 624B Making a String
- Codeforces AIM Tech Round (Div. 1)623A Graph and String
- Codeforces AIM Tech Round (Div. 2)解题报告