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. 前端基础-JavaScript的基本概述和语法

    1.JavaScript概述 2.JavaScript引入方式 3.JavaScript语言规范 4.JavaScript语言基础 5.JavaScript数据类型 6.JavaScript运算符 7 ...

  2. Exercise01_03

    public class TuAn{ public static void main(String[] args){ System.out.println(" J A V V A" ...

  3. 《ggplot2:数据分析与图形艺术》,读书笔记

    第1章 简介 1.3图形的语法 第2章从qplot开始入门 1.基本用法:qplot(x,y,data) x是自变量横轴,y是因变量纵轴,data是数据框   2.图形参数 colour=I(&quo ...

  4. Delphi 自动检测U盘插入、拔出及获取U盘盘符!

    http://qqhack8.blog.163.com/blog/static/1141479852012102133475/     Delphi 自动检测U盘插入.拔出及获取U盘盘符! u盘的 插 ...

  5. 【tomcat】FileNotFoundException: C:\Program Files\Java\apache-tomcat-8.5.11-geneshop3\webapps\ROOT\index.html (拒绝访问。)

    新装系统后,tomcat启动起来 提示如下错误: Caused by: java.io.FileNotFoundException: C:\Program Files\Java\apache-tomc ...

  6. WebLogic Server的密码复杂性规则设置

    WebLogic Server默认的密码复杂性规则是长度为8位以上,必须包含数字和字母,但对于很多企业的安全而言是不足够的,因此WebLogic Server在Security模块中提供了Passwo ...

  7. linux使用其它用户 su - op -c

    su - op -c "whoami"

  8. scrapy-splash抓取动态数据例子十四

    一.介绍 本例子用scrapy-splash爬取超级TV网站的资讯信息,输入给定关键字抓取微信资讯信息. 给定关键字:数字:融合:电视 抓取信息内如下: 1.资讯标题 2.资讯链接 3.资讯时间 4. ...

  9. Android使用tcpdump抓包

    AllJoyn中有个问题:Server切换到Client后,重新加入其他Server时join session会失败,原因是timeout(join session是异步的,在指定时间内没有收到回应) ...

  10. 绝对让你理解Android中的Context

    这个问题是StackOverFlow上面一个热门的问题What is Context in Android? 整理这篇文章的目的是Context确实是一个非常抽象的东西.我们在项目中随手都会用到它,但 ...