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;
    }
    
  • 相关阅读:
    个人总结
    第十六周学习进度条
    第二阶段冲刺第十天
    第二阶段冲刺第九天
    分层体系架构模式
    安卓语音识别
    AndroidStudio中导入jar包的方法
    Android中控件之间添加分割线
    按照分层设计理念,完成《XXX需求征集系统》的概念结构设计
    在Eclipse下搭建Hibernate框架(加载hibernate工具插件,离线)
  • 原文地址:https://www.cnblogs.com/gidear/p/11773646.html
Copyright © 2011-2022 走看看