codeforces624B Making a String 贪心 排序

团体程序设计天梯赛-练习集 L2-2. 链表去重 数组模拟链表 L2-2. 链表去重 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个带整数键值的单链表L,本题要求你编写程序,删除那些键值的绝对值有重复的结点。即对任意键值K,只有键值或其绝对值等于K的第一个 阅读详情

B. Making a String
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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".



从大到小排序,用一个map来唯一标示,遇到标记过的不断减一,直到减到这个数之前没有出现过,累加,依次进行到底


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

int a[30];
map<int, int> m;

bool cmp(int x, int y) {
	return x > y;
}

int main()
{
	int n;
	while (~scanf("%d", &n)) {
		m.clear();
		for (int i = 0; i < n; i++) {
			scanf("%d", &a[i]);
		}
		sort(a, a + n, cmp);
		long long ans = 0;
		for (int i = 0; i < n; i++) {
			if (m[a[i]] == 0) {
				m[a[i]]++;
				ans += a[i];
			} else {
				while (a[i] > 0) {
					if (m[--a[i]] == 0) {
						m[a[i]]++;
						ans += a[i];
						break;
					}
				}
			}
		}
		printf("%I64d\n", ans);
	}
	return 0;
}





杰理蓝牙SPP用户接口详细文档 本文档详细介绍了基于JL701n芯片的蓝牙SPP用户接口实现。主要内容包括:1) 文件结构分析,包含必要的头文件和调试配置;2) 核心数据结构,如全局变量和TWS功能ID定义;3) 五大功能模块实现:数据发送、状态管理、数据接收、TWS支持和初始化清理;4) API接口说明,包括公共接口函数和回调函数;5) 使用教程,涵盖基本流程和高级应用示例。该接口支持虚拟串口连接,实现蓝牙设备间数据传输,特别针对TWS场景进行了优化,提供连接状态管理、数据收发等功能。文档还包含错误处理、重试机制等实用建议,适合蓝牙SP 阅读详情

相关推荐

MaxDEA如何计算超效率DEA

MaxDEA如何计算超效率DEA第一步,导入数据,设置输出和输出,点击OK;第二步,运行模型; 本文计算的是超效率DEA-BCC。 第一步,导入数据,设置输出和输出,点击OK; 第二步,运行模型; 在distance选项框中选择Radial:CCR(1978);BCC(1984)。 在Orientation中选择Non-oriented。其中,Input-oriented是投入最小;Outp...

王樰沫 1万+

B. Making a String【水题】

time limit per test  1 second memory limit per test  256 megabytes input  standard input output  standard output You are given an alphabet consisting of n letters, your task

Joeferyの博客 717

Stata实战入门:从数据导入到基础分析的全流程指南

本文提供了Stata实战入门的全流程指南,从数据导入、清洗到基础分析和可视化,帮助初学者快速掌握Stata的核心功能。通过详细的步骤和实用技巧,读者可以高效完成数据处理、变量操作、描述性统计和回归分析等任务,提升数据分析效率。

weixin_28327051的博客 395

CodeForces 624B Making a String(贪心)

题意:有n个字母,每个字母最多出现ai次,但是每个字母的出现次数都要求不一样,问你这个字符串最长多长思路:显然从大到小排序,然后贪心就好了,能选就选,不能选就–就行了#include<bits/stdc++.h> using namespace std;int a[30]; map<int,int> H; int main() { int n;scanf("%d",&n); for(

围巾的ACM博客 735

从示波器波形看懂CAN/RS485/RS422:一个TVS管放错位置,通信全挂的教训

本文通过示波器波形分析,深入探讨了CAN/RS485/RS422通信系统中TVS管布局错误的故障诊断与解决方案。文章详细解析了错误布局导致的波形特征,如信号钳位、阻抗失配等,并提供了正确的保护电路设计方案和终端匹配技术,帮助工程师快速定位和解决通信故障。

weixin_30555515的博客 356

203.华为组网实例:VLAN间互通DHCP中继实验

SW核心交换机上配置DHCP中继。

迷逝 8440

B. Making a String

time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an alphabet consisting of n letters, your task is t

无知的我 1155

uniapp - 应用软件在运行时,未见向用户告知权限申请的目的,向用户索取(存储、相机、电话)等权限,不符合华为应用市场审核标准(uniApp开发安卓APP上架应用市场审核被拒绝驳回,详细解决方案)

uniApp应用软件在运行时,未见向用户告知权限申请的目的,向用户索取(存储、相机、电话)等权限,不符合华为应用市场审核标准。uniapp vue2 vue3解决软件在运行时,未见向用户告知权限申请的目的,华为等上架被拒问题,关于华为应用市场上架需要同步告知使用权限的解决方案,uniApp应用软件在运行时,不符合华为应用市场审核标准。解决方案合集!app上架-您的应用在运行时,未同步告知权限申请的使用目的,向用户索取(相机)等权限,不符合华为应用市场审核标准。华为应用市场审核新规(未同步告知权限申请的使用目

🏆 前端领域优质创作者 4177

CodeForces 624B - Making a String

贪心 #include #include #include using namespace std; const int MAX = 30; __int64 arr[MAX]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%I64d", &arr[i]); sort(ar

菜鸟 557

Python实现商品价格监控与波动分析爬虫项目

本文通过完整的代码示例和详细的技术讲解,展示了如何实现商品价格的自动监控和波动分析。该项目不仅适用于个人购物助手,还可以扩展为商家的竞品监控工具。通过结合数据抓取、存储、分析与可视化,能够帮助我们更好地理解市场趋势并做出优化决策。

2201_76125261的博客 1752

YOLOv4目标检测算法——通俗易懂的解析

YOLOv4目标检测算法——通俗易懂的解析

chase 7140

Making a String

链接:http://codeforces.com/problemset/problem/624/B 题目: 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 cond

veget_chicken的博客 388

手把手教你学Simulink--基于储能系统的建模与仿真场景:-锂电池储能系统充放电管理策略仿真

《锂电池储能系统充放电管理的Simulink建模与仿真》摘要 本文详细介绍了使用Simulink+SimscapeElectrical对锂电池储能系统进行充放电管理策略建模的全过程。从系统结构设计入手,重点阐述了锂电池模型、充放电控制器、热管理系统等核心模块的搭建方法,并提供了完整的仿真流程。文章详细说明了如何实现荷电状态管理、温度控制和功率限制等关键策略,通过仿真分析了电池电压、电流、SoC和温度等关键指标的变化规律。最后提出了基于仿真结果的优化建议,包括参数整定、算法改进等方面,为锂电池储能系统的安全高

MHD0815的博客 1万+

AIM Tech Round (Div. 2) B. Making a String 贪心

题目链接:codeforces.com/contest/624/problem/B 题意:有n个字母,每个字母最多出现ai次,但是每个字母的出现次数都要求不一样 问你这个字符串最长多长? 解法:显然从大到小排序,然后贪心就好了,能选就选,不能选就--就行了 注意小心被减到负数了 //CF 624B #include <bits/stdc++.h> us...

aishangg437965的博客 115

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Codeforces 624B Making a String 【水题】

B. Making a String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an alphabet consisting of n

世界很大 596

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

CodeForces 624B Making a String

codeforces 624B 方法比较低效。。 #include #include #include #include using namespace std; bool cmp(int a, int b) { return a > b; } int a[30]; int main() { int N; while(~scanf("%d", &N)){ int i, j;

Benjamin_Z的博客 550

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Codeforces AIM Tech Round (Div. 2) B. Making a String

B. Making a String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an alphabet consisting of n letters,

滴水穿石,慢慢积累,总会有成果 615

AIM Tech Round (Div. 2)题解

A. Save LukeLuke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assum

long-long-ago 1127

B - Making a String-----CodeForces 624B

B - Making a String Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 624B Description You are given an alphabet consistin

海水梦悠悠的博客 780

hdu计算机学院大学生程序设计竞赛 2015’11 1002 投币洗衣机

投币洗衣机 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5966    Accepted Submission(s): 1495 Problem Description   如今大学生的生活条件越来越好了,近期

EventQueue的博客 1440

poj2249 Binomial Showdown 求组合数

Binomial Showdown Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18925   Accepted: 5788 Description In how many ways can you choose k elements out of n el

EventQueue的博客 1278

qduoj61 统计人数

统计人数 发布时间: 2015年12月14日 15:36   最后更新: 2015年12月14日 17:59   时间限制: 1000ms   内存限制: 32M 描述 HS想要统计镇上总共有多少人,但是他并不想一个一个的去数有多少个人,他想了一个其他的方法,他在镇上找了N个人,然后问每一个人“你知道 除你之外 镇上和你姓氏相同的人有多少个吗?”,现在HS想要知道,镇上最少有

EventQueue的博客 1047

hdu计算机学院大学生程序设计竞赛(2015’11)1004 质方数

质方数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3381    Accepted Submission(s): 1134 Problem Description   小明天生对数字比较敏感,3岁的时

EventQueue的博客 949

hdu计算机学院大学生程序设计竞赛(2015’11)1008 游乐场

游乐场 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4876    Accepted Submission(s): 757 Problem Description   小时候,因为家里经济困难,小明从未

EventQueue的博客 920

pat甲级 1020. Tree Traversals map递归建树 + BFS

先用map建立一棵二叉树,mr存右孩子节点,ml存左孩子节点,然后输出BFS路径就行了 #include #include #include #include #include using namespace std; int N; int po[35], in[35], prin[35]; int root, ip, len; map ml, mr; int solve

EventQueue的博客 903
上一篇: poj3235 Fence Repair 优先队列 哈弗曼树
下一篇: poj1190 生日蛋糕 dfs神剪枝
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址