zoukankan      html  css  js  c++  java
  • 2019/4/20周赛 F题 CodeForces

    2019/4/20周赛 F题

    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.

    Examples
    Input
    3
    2 5 5
    Output
    11
    Input
    3
    1 1 2
    Output
    3
    Note
    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”.
    题目大意:输入n个数字每个数字都要使其不相同,求其sum(求和)最大值。

    #include<cmath>
    #include <iostream>
    #include<stdio.h>
    #include<algorithm>
    #include<vector>
    using namespace std;
    typedef long long LL;
    
    int main()
    {
    	int n,flag=0;
    	LL a[30], sum=0 ;
    	cin >> n;
    	for (int i = 0; i < n; i++)
    	{
    		cin >> a[i];
    	}
    	sort(a, a + n);
    	sum = a[n - 1];
    	for (int i = n - 2; i >= 0; i--)
    	{
    		while (a[i] >= a[i + 1])//>=是精髓能够使其推下去
    			a[i]--;
    		if (a[i] < 0)
    			a[i] = 0;
    		sum += a[i];
    	}
    	cout << sum << endl;
        return 0;
    }
    
  • 相关阅读:
    ES5 05 Function扩展
    ES5 04 Array扩展
    ES5 03 Object扩展
    ES5 02 JSON对象
    ES5 01 严格模式
    Oracle 数据库复制
    PB函数大全
    Handle( ) //得到PB窗口型对象的句柄
    PB赋值粘贴 多个DW进行update
    pb 11 数据窗口空白,预览pb崩溃解决方案
  • 原文地址:https://www.cnblogs.com/gidear/p/11773646.html
Copyright © 2011-2022 走看看