题意(CodeForces 614D)

每个人有\(n(n\le 10^5)\)个技能,技能等级都在\([0,10^9]\)的范围,每个技能有一个当前等级,所有技能的最高等级都为A。一个人的力量被记做以下两项的和:

1. 顶级技能的个数 *cf

2. 最低等级的技能 *cm

每个单位的钱能够提升一级力量。我们希望花尽可能少的钱,使得力量尽可能高。

分析

我二分的功力还是不足,要多努力。这题其实是一个非常明显的暴力:我们枚举提高到A的等级的个数(到不能提升为止),枚举这种情况下,我们能够令把多少人的等级提升到相同的某个等级——这个地方可以用二分解决(先排序)。这样遍历一遍整个等级,就能得到最优的策略,然后输出答案即可。具体的代码细节见注释。

代码

/*
* Filename: cfr339d2d.cpp
* Date: 2018-11-07
*/ #include <bits/stdc++.h> #define INF 0x3f3f3f3f
#define PB emplace_back
#define MP make_pair
#define fi first
#define se second
#define rep(i,a,b) for(repType i=(a); i<=(b); ++i)
#define per(i,a,b) for(repType i=(a); i>=(b); --i)
#define ZERO(x) memset(x, 0, sizeof(x))
#define MS(x,y) memset(x, y, sizeof(x))
#define ALL(x) (x).begin(), (x).end() #define QUICKIO \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define DEBUG(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) using namespace std;
using pi=pair<int,int>;
using repType=int;
using ll=long long;
using ld=long double;
using ull=unsigned long long; const int MAXN=100005; struct Skill
{
int v,o;
Skill() {}
Skill(int _v, int _o):v(_v), o(_o) {}
} a[MAXN]; int n;
ll A,cf,cm,m,sum[MAXN]; int solve(int R, ll now) // given present cost, and r which tells 1~r are not A,
{ // which lowest lv can you reach?
if(R==0) return A;
int l=1, r=R;
while(l<r)
{
int mid=(l+r+1)/2;
ll need=ll(a[mid].v)*mid-sum[mid]; // we need it to make pre n people
if (need>now) r=mid-1; else l=mid; // reach the lv of the nth.
}
ll need=ll(a[l].v)*l-sum[l];
ll more=(now-need)/l;
return min(ll(A), a[l].v+more);
} int
main()
{
scanf("%d%lld%lld%lld%lld", &n, &A, &cf, &cm, &m);
rep(i,1,n)
{
scanf("%d", &a[i].v);
a[i].o=i;
}
sort(a+1, a+n+1, [](Skill& x, Skill& y) -> bool
{
return x.v<y.v;
});
a[n+1].v=A; rep(i,1,n) sum[i]=sum[i-1]+a[i].v; ll ans=-1, cost=0;
int v,p;
per(i,n,0)
{
cost+=A-a[i+1].v; if(cost>m) break;
int minv=solve(i,m-cost);
ll tmp=minv*cm+(n-i)*cf;
if(tmp>ans)
{
ans=tmp;
p=i;
v=minv;
}
} printf("%lld\n", ans);
per(i,n,p+1) a[i].v=A;
rep(i,1,p) a[i].v=max(a[i].v, v);
sort(a+1, a+n+1, [](Skill& x, Skill& y) -> bool
{
return x.o<y.o;
});
rep(i,1,n)
printf("%d ", a[i].v);
printf("\n"); return 0;
}

「日常训练」Skills(Codeforce Round #339 Div.2 D)的更多相关文章

  1. 「日常训练」ZgukistringZ(Codeforces Round #307 Div. 2 B)

    题意与分析(CodeForces 551B) 这他妈哪里是日常训练,这是日常弟中弟. 题意是这样的,给出一个字符串A,再给出两个字符串B,C,求A中任意量字符交换后(不限制次数)能够得到的使B,C作为 ...

  2. 「日常训练」Watering Flowers(Codeforces Round #340 Div.2 C)

    题意与分析 (CodeForces 617C) 题意是这样的:一个花圃中有若干花和两个喷泉,你可以调节水的压力使得两个喷泉各自分别以\(r_1\)和\(r_2\)为最远距离向外喷水.你需要调整\(r_ ...

  3. 「日常训练」Alternative Thinking(Codeforces Round #334 Div.2 C)

    题意与分析 (CodeForces - 603A) 这题真的做的我头疼的不得了,各种构造样例去分析性质... 题意是这样的:给出01字符串.可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所 ...

  4. 「日常训练」More Cowbell(Codeforces Round #334 Div.2 B)

    题意与分析(CodeForces 604B) 题意是这样的:\(n\)个数字,\(k\)个盒子,把\(n\)个数放入\(k\)个盒子中,每个盒子最多只能放两个数字,问盒子容量的最小值是多少(水题) 不 ...

  5. 「日常训练」Duff in the Army (Codeforces Round #326 Div.2 E)

    题意(CodeForces 588E) 给定一棵\(n\)个点的树,给定\(m\)个人(\(m\le n\))在哪个点上的信息,每个点可以有任意个人:然后给\(q\)个询问,每次问\(u\)到\(v\ ...

  6. 「日常训练」Kefa and Dishes(Codeforces Round #321 Div. 2 D)

    题意与分析(CodeForces 580D) 一个人有\(n\)道菜,然后要点\(m\)道菜,每道菜有一个美味程度:然后给你了很多个关系,表示如果\(x\)刚好在\(y\)前面做的话,他的美味程度就会 ...

  7. 「日常训练」Kefa and Park(Codeforces Round #321 Div. 2 C)

    题意与分析(CodeForces 580C) 给你一棵树,然后每个叶子节点会有一家餐馆:你讨厌猫(waht?怎么会有人讨厌猫),就不会走有连续超过m个节点有猫的路.然后问你最多去几家饭店. 这题我写的 ...

  8. 「日常训练」Kefa and Company(Codeforces Round #321 Div. 2 B)

    题意与分析(CodeForces 580B) \(n\)个人,告诉你\(n\)个人的工资,每个人还有一个权值.现在从这n个人中选出m个人,使得他们的权值之和最大,但是对于选中的人而言,其他被选中的人的 ...

  9. 「日常训练」Case of Matryoshkas(Codeforces Round #310 Div. 2 C)

    题意与分析(CodeForces 556C) 为了将所有\(n\)个娃娃编号递增地串在一起(原先是若干个串,每个串是递增的), 我们有两种操作: 拆出当前串中最大编号的娃娃(且一定是最右边的娃娃). ...

随机推荐

  1. php无极限分类函数

    /** * [make_tree description] * @Author Lerko * @DateTime 2017-04-01T14:57:24+0800 * @param [type] $ ...

  2. 用Java+xml配置方式实现Spring数据事务(编程式事务)

    一.用Java配置的方式 1.实体类: Role public class Role { private int id; private String roleName; private String ...

  3. 安装mysql的时候提示1045错误的解决方法

    在安装mysql的时候提示1045错误,如图所示: 这种情况一般是之前卸载msyql的时候没有清理完一些文件之类的,导致给你提示存在安全问题,因此,只需要找到mysql一些系统的配置文件,并且将他们删 ...

  4. 微信小程序,搜索结果关键词高亮 wxml不能动态识别html标签

    wxml中使用rich-text标签放置动态html标签 js:

  5. Java中的IO流(四)

    上一篇<Java中的IO流(三)>把IO流中的文件及目录操作的对象File类记录了一下,本篇把本不属性IO流但又和IO流有关系的一个对象作一下记录,此对象本属于集合框架里的一个子集,即Pr ...

  6. shutil.rmtree()

    shutil.rmtree(path, ignore_errors=False, onerror=None)   #递归地删除文件 def rmtree(path, ignore_errors=Fal ...

  7. openresty 配置 mongodb 可操作插件

    1.下载lua-resty-mongol https://github.com/bigplum/lua-resty-mongol 2.配置_mongo.conf文件,在conf创建_mongo.con ...

  8. Angular.js进阶

    1.常用指令 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UT ...

  9. webuploader的一个页面多个上传按钮实例

    借鉴一位大佬的demo  附上他的github地址https://github.com/lishuqi 我把他的cxuploader.js改了不需要预览  直接上传图片后拿到回传地址给img标签显示图 ...

  10. git 项目常用

    本地分支推送到远程分支: (1),git init,git add . (2),git commit -m "首次提交" (3),git remote add origin '远程 ...