Codeforces 624
1 second
256 megabytes
standard input
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.
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.
Print a single integer — the maximum length of the string that meets all the requirements.
3
2 5 5
11
3
1 1 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".
题目的意思就是,给定你每个字母可以出现的次数,然后根据题目中的两个条件,计算最后字符串可能的最大长度。
条件一,每个字母最多出现给定的 ai 次;条件二,不能有两个字母出现的次数相同。ok,我用了一个set。
package Sunny; import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner; /**
* Created by lenovo on 2016-05-05.
*/
public class CF624B {
public static void main(String[] args){
Scanner scanner = new Scanner(new InputStreamReader(System.in));
int n = scanner.nextInt();
long[] arr = new long[26];
for(int i = 0; i < n; ++i){
arr[i] = scanner.nextLong();
} Arrays.sort(arr);
long num = 0; long ans = 0;
HashSet<Long> set = new HashSet<Long>();
for(int i = 25; i >= 0; --i){
while(set.contains(arr[i])){
arr[i]--;
}
set.add(arr[i]);
}
long tmp;
Iterator<Long> iterator = set.iterator();
while(iterator.hasNext()){
tmp = iterator.next();
if(tmp > 0)
ans += tmp;
}
System.out.println(ans);
}
}
Codeforces 624的更多相关文章
- Codeforces #624 div3 C
You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
- CODEFORCES ROUND#624 DIV3
这次比赛从名字就可以看出非常水,然鹅因为第一次打codeforces不太熟悉操作只来的及做签到题(还错了一次) A,B,C都是签到题考点思维就不写了 D题 https://codeforces.ml/ ...
- Codeforces Round #624 (Div. 3) F. Moving Points 题解
第一次写博客 ,请多指教! 翻了翻前面的题解发现都是用树状数组来做,这里更新一个 线段树+离散化的做法: 其实这道题是没有必要用线段树的,树状数组就能够解决.但是个人感觉把线段树用熟了会比树状数组更有 ...
- Codeforces Round #624 (Div. 3) C. Perform the Combo(前缀和)
You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...
- 详细讲解Codeforces Round #624 (Div. 3) E. Construct the Binary Tree(构造二叉树)
题意:给定节点数n和所有节点的深度总和d,问能否构造出这样的二叉树.能,则输出“YES”,并且输出n-1个节点的父节点(节点1为根节点). 题解:n个节点构成的二叉树中,完全(满)二叉树的深度总和最小 ...
- 详细讲解Codeforces Round #624 (Div. 3) F. Moving Points
题意:给定n个点的初始坐标x和速度v(保证n个点的初始坐标互不相同), d(i,j)是第i个和第j个点之间任意某个时刻的最小距离,求出n个点中任意一对点的d(i,j)的总和. 题解:可以理解,两个点中 ...
- Codeforces Round #624 (Div. 3)
A.题意:通过加奇数减偶数的操作从a到b最少需要几步 签到题 #include <algorithm> #include <iostream> #include <cst ...
- Codeforces Round #624 (Div. 3) B. WeirdSort(排序)
output standard output You are given an array aa of length nn . You are also given a set of distinct ...
随机推荐
- Appcan——Box
Box架构 ub….. Box架构元素空间大小分配比例 ub-f……. Ub-f1,ub-f2,ub-f3……. Box架构元素垂直方向的位置排列 ub-ac,ub-ae… -webkit-box-a ...
- 如何添加商*通新对话快捷链接?不用js代码
我们在使用商务通一般都是在页面中嵌入一段js代码,如果您是js洁癖,是不是在想着如何直接用一张小图加上商*通新对话链接来代替呢?好,那就一起来研究一下吧. 首先,我们打开一个有商*通js弹窗的页面,比 ...
- MarkdownPad 2 在win10下出错:HTML 渲染错误(This view has crashed) 的解决办法 + MarkdownPad2.5 注册码
首先附上MarkdownPad2.5的注册码. 邮箱:Soar360@live.com 授权密钥: GBPduHjWfJU1mZqcPM3BikjYKF6xKhlKIys3i1MU2eJHqWGImD ...
- AndroidStudio非法字符: '\ufeff'解决
一. 问题解决办法 在昨天,帮助同学把他的Android项目从eclipse迁移到Android Studio上面的时候,编译时,Android Studio报了一个错误, ***.java Erro ...
- 【spoj705】 Distinct Substrings
[题目描述] 给定一个字符串,计算其不同的子串个数. [输入格式] 一行一个仅包含大写字母的字符串,长度<=50000 [输出格式] 一行一个正整数,即不同的子串个数. [样例输入] ABABA ...
- springMVC接受JSON异常
在springMVC 使用@RequestBody接受Json总是报如下错误: HTTP Status 500 - Handler processing failed; nested exceptio ...
- Session的属性
Session的属性 Session在网络应用中被称为会话.具体到web中的Session指的就是用户在浏览某个网站时,从进入网站到浏览器关闭所经过的这段时间,也就是用户浏览这个网站所花费的时间,因 ...
- Qt在ui中使用代码添加新的控件
QLabel* label = new QLabel(ui->centralWidget);
- Servlet引擎tomcat之安装
原文来自:https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-14-04 ...
- Ajax请求跨域问题 -- 转载
几乎每种浏览器都存在默认的安全机制,都有同源策略,因为浏览器恶意的把每个外部请求的都当做是黑客攻击,相当于是对自身的保护,所以浏览器在运行脚本时会判断脚本与请求的页面是否是同一来源,这个同一来源,包括 ...