zoukankan      html  css  js  c++  java
  • codeforces624b Making a String

     
    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[26];
    bool cmp(int a,int b){
        return a>b;
    }
    int main(){
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        int tmp=0;
        long long ans=0;
        sort(a,a+n,cmp);
        ans+=a[0];
        tmp=a[0];
        for(int i=1;i<n;i++){
            if(a[i]>=tmp) tmp=tmp-1;
            else tmp=a[i];
            if(tmp<=0) break;
            ans+=tmp;
        }
        printf("%I64d
    ",ans);
        return 0;
    }
    View Code
  • 相关阅读:
    用Chrome和android SDK远程调试移动端页面
    如何配置能让fiddler抓去https的请求?
    开源免费的简易中文分词系统SCWS – PHP版
    Node.js 开发环境搭建及设置
    linux 安装 git server
    linux下 删除乱码文件名
    PowerDesigner 使用问题
    linux 设置开机大全
    mysql 实现 row_number() over(pattition by a order by b )
    WebApi Filter 中断返回字符串信息
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/5686207.html
Copyright © 2011-2022 走看看