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
  • 相关阅读:
    Assetbundle创建与加载
    11个超棒的iOS开发学习网站
    UGUI
    Unity3D教程宝典之Shader篇
    解决ngui挡住粒子的问题
    unity 随笔
    进程与线程浅析
    c#语言
    Unity3D中使用委托和事件
    Unity3D中常用的数据结构总结与分析
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/5686207.html
Copyright © 2011-2022 走看看