Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

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 Input

Input
3
2 5 5
Output
11
Input
3
1 1 2
Output
3

Hint

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

#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int a[];
bool cmp(int a,int b){
return a>b;
}
int main(){
int n;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
int tmp=;
long long ans=;
sort(a,a+n,cmp);
ans+=a[];
tmp=a[];
for(int i=;i<n;i++){
if(a[i]>=tmp) tmp=tmp-;
else tmp=a[i];
if(tmp<=) break;
ans+=tmp;
}
printf("%I64d\n",ans);
return ;
}

codeforces624b Making a String的更多相关文章

  1. 透过WinDBG的视角看String

    摘要 : 最近在博客园里面看到有人在讨论 C# String的一些特性. 大部分情况下是从CODING的角度来讨论String. 本人觉得非常好奇, 在运行时态, String是如何与这些特性联系上的 ...

  2. JavaScript String对象

    本编主要介绍String 字符串对象. 目录 1. 介绍:阐述 String 对象的说明以及定义方式. 2. 实例属性:介绍 String 对象的实例属性: length. 3. 实例方法:介绍 St ...

  3. ElasticSearch 5学习(9)——映射和分析(string类型废弃)

    在ElasticSearch中,存入文档的内容类似于传统数据每个字段一样,都会有一个指定的属性,为了能够把日期字段处理成日期,把数字字段处理成数字,把字符串字段处理成字符串值,Elasticsearc ...

  4. [C#] string 与 String,大 S 与小 S 之间没有什么不可言说的秘密

    string 与 String,大 S 与小 S 之间没有什么不可言说的秘密 目录 小写 string 与大写 String 声明与初始化 string string 的不可变性 正则 string ...

  5. js报错: Uncaught RangeError: Invalid string length

    在ajax请求后得到的json数据,遍历的时候chrome控制台报这个错误:Uncaught RangeError: Invalid string length,在stackoverflow查找答案时 ...

  6. c# 字符串连接使用“+”和string.format格式化两种方式

    参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ...

  7. 【手记】注意BinaryWriter写string的小坑——会在string前加上长度前缀length-prefixed

    之前以为BinaryWriter写string会严格按构造时指定的编码(不指定则是无BOM的UTF8)写入string的二进制,如下面的代码: //将字符串"a"写入流,再拿到流的 ...

  8. JavaScript中String对象的方法介绍

    1.字符方法 1.1 charAt() 方法,返回字符串中指定位置的字符. var question = "Do you like JavaScript?"; alert(ques ...

  9. 在多线程编程中lock(string){...}隐藏的机关

    常见误用场景:在订单支付环节中,为了防止用户不小心多次点击支付按钮而导致的订单重复支付问题,我们用 lock(订单号) 来保证对该订单的操作同时只允许一个线程执行. 这样的想法很好,至少比 lock( ...

随机推荐

  1. springmvc与前端数据交互实例

      一.从页面接收参数 Spring MVC接收请求提交的参数值的几种方法: 使用HttpServletRequest获取. @RequestMapping("/login.do" ...

  2. 【R笔记】R语言进阶之4:数据整形(reshape)

    R语言进阶之4:数据整形(reshape) 2013-05-31 10:15 xxx 网易博客 字号:T | T 从不同途径得到的数据的组织方式是多种多样的,很多数据都要经过整理才能进行有效的分析,数 ...

  3. 用 HTML 元素实现自定义的滚动条

    有时,浏览器默认的滚动条不能满足需求,我们要实现自定义的滚动条.借助于鼠标移动事件和滚轮事件,以及内容元素的滚动相关属性,可以很容易地实现这样的需求.下面就来试一试. 我们这次要实现的滚动条需要有以下 ...

  4. 一个简单的WeakList的实现

    有的时候,我们会使用到WeakList,它和传统的List不同的是,保存的是对象的弱应用,在WeakList中存储的对象会被GC回收,在一些和UI相关的编程的地方会用到它(弱事件,窗体的通知订阅等). ...

  5. sql-server-linux 官网

    https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-overview

  6. SSL和TSL的区别【转】

    SSL由从前的网景公司开发有1,2,3三个版本,但现在只使用版本3 TLS是SSL的标准化后的产物 有1.0 1.1 1.2三个版本 默认使用1.0 TLS1.0和SSL3.0几乎没有区别 事实上我们 ...

  7. 快速开发框架(FDMS)新增1000个对外接口都不须要手写一行代码

    一个大型系统难免会跟其它系统有数据交换,这里就要提供数据接口给外部系统. 曾经在一家智能终端设备的公司上班.那段时间的主要工作就是写接口.接口须要与手机.手持设备.系统管理软件等进行数据交换.总结了一 ...

  8. docker 实现redis集群搭建

    摘要:接触docker以来,似乎养成了一种习惯,安装什么应用软件都想往docker方向做,今天就想来尝试下使用docker搭建redis集群. 首先,我们需要理论知识:Redis Cluster是Re ...

  9. 安装完office2016 64位后,在安装visio时,报错,无法安装,

    安装环境要求: 系统要求:win8,win10等: office要求:sw(批量版)不能和cn(零售版).365版混装.-------重点注意事项 一定要注意批量版和零售版的区别,各版本之间绝对不允许 ...

  10. spring常用的一些注解以及注解注入总结

    常用的spring注解有如下几种: @Controller@Service@Autowired@RequestMapping@RequestParam@ModelAttribute@Cacheable ...