Skills
题目描述
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly $n$ skills. Each skill is represented by a non-negative integer $a_i$ — the current skill level. All skills have the same maximum level $A$.
Along with the skills, global ranking of all players was added. Players are ranked according to the so-called Force. The Force of a player is the sum of the following values:
- The number of skills that a character has perfected (i.e., such that $a_i=A$), multiplied by coefficient $c_f$.
- The minimum skill level among all skills ($\min(a_i)$), multiplied by coefficient $c_m$.
Now Lesha has $m$ hacknetian currency units, which he is willing to spend. Each currency unit can increase the current level of any skill by $1$ (if it’s not equal to $A$ yet). Help him spend his money in order to achieve the maximum possible value of the Force.
题意概述
给定$n$个技能,第$i$个技能的等级为$a_i$。所有技能的最高等级为$A$。你有$m$个技能点,每个技能点可以让某个技能升$1$级。给定两个数$c_f, c_m$,定义所有技能的价值总和为$c_f$乘满级技能的个数加$c_m$乘所有技能的最低等级。求价值总和的最大值。
数据范围:$1 \le n \le 10^5, \ 1 \le A \le 10^9, \ 0 \le c_f, c_m \le 1000, \ 0 \le m \le 10^{15}$。
算法分析
将技能按等级从小到大排序。记录两个指针$p, q$,$p$指针之后的技能都已满级,$q$指针之前的技能的等级极差不大于$1$。先计算出$p$的最小值,接着依次枚举$p$,同时根据贪心策略,前$q$个技能的等级越平均越好。这样就可以计算出答案。
代码
1 |
|