题目描述:

有一个oier,他有n个算法技能,每个技能有一个水平值,每个技能的水平上限都是A,设这个oier有cnt个技能达到了A, 设所有水平值的最小值为mi,那么这个oier的战斗力为cnt×Cf+mi×Cm,现在这个oier准备去提升自己的技能,他有m次提升的机会,每次提升可以选择某一个技能给水平值加1,如何分配这些提升的机会,来使得自己的战斗力总值最大?

输入格式:

第一行输入5个整数,n,A,Cf,Cm,m

第二行输入n个整数,表示每个技能的水平值

输出格式:

输出最大战斗力值

样例输入:

3 5 10 1 5
1 3 1

样例输出:

12

约定:

1≤n≤100000,1≤A≤10^9,0≤Cf,Cm≤1000,0≤m≤10^15

题解:考虑贪心的策略,由于只有将一个技能点到A或者提升最低技能等级才能增加战斗力,所以说,只有两种操作是有意义的

1.将一个技能点到A

2.将所有最低等级的技能都点高一级,相当于提升最低等级一级

所以我们可以从1-n枚举将i个技能点到a级所需要的最小花费,这个东西sort一下就能搞了,显然点满最大的前i个花费最小,然后用剩下的技能点高最低技能,其思路就相当于把剩下的水倒进低洼,去获得此时水的高度一样

这个高度显然是可以二分的

用lower_bound搞出高度大于等于high的第一个位置pos,然后显然pos-1位置都是要填的,至于要填多少,显然可以维护一个前缀和记录已经填了多少了,再用high*(pos-1)-这个数就可以知道你要填多少,然后和你还剩的数比下哪个大就知道了,这东西是单调的,所以可以二分

不过要注意如果你已经把i个数点到A了,那么pos的最大位置也就是n-i了

其次开局已经到A的技能还要特殊处理一下

代码如下:

#include<deque>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mod 1000000007
using namespace std; long long a[],n,aa,cf,cm,m,sum[],tot; int check(long long high,long long remain,int now)
{
if(high>aa) return ;
int pos=lower_bound(a+,a+n+,high)-a;
if(pos>n-now) pos=n-now+;
if(remain>=high*(pos-)-sum[pos-])
{
return ;
}
return ;
} int main()
{
scanf("%lld%lld%lld%lld%lld",&n,&aa,&cf,&cm,&m);
for(int i=; i<=n; i++)
{
scanf("%lld",&a[i]);
}
sort(a+,a+n+);
while(a[n]==aa)
{
tot++;
n--;
}
for(int i=;i<=n;i++)
{
sum[i]=sum[i-]+a[i];
}
long long cnt=,ans=;
long long l=,r=1e9,mid,re=m-cnt;
while(l<=r)
{
mid=(l+r)>>;
if(check(mid,re,))
{
l=mid;
}
else
{
r=mid-;
}
if(r-l<=)
{
r=check(r,re,)?r:l;
break;
}
}
ans=r*1ll*cm+tot*1ll*cf;
for(int i=; i<=n; i++)
{
cnt+=aa-a[n-i+];
if(cnt>=m)
{
break;
}
long long l=,r=1e9,mid,re=m-cnt;
while(l<=r)
{
mid=(l+r)>>;
if(check(mid,re,i))
{
l=mid;
}
else
{
r=mid-;
}
if(r-l<=)
{
r=check(r,re,i)?r:l;
break;
}
}
ans=max(1ll*(i+tot)*cf+1ll*r*cm,ans);
}
printf("%lld\n",ans);
}

思路其实很简单,但是真的是细节很多啊QAQ

XJOI 3601 技能(贪心+二分)的更多相关文章

  1. poj 2782 Bin Packing (贪心+二分)

    F - 贪心+ 二分 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Description ...

  2. Card Game Cheater(贪心+二分匹配)

    Card Game Cheater Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  3. The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - F 贪心+二分

    Heap Partition Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge A sequence S = { ...

  4. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...

  5. Codeforces Round #768 (Div. 2) D. Range and Partition // 思维 + 贪心 + 二分查找

    The link to problem:Problem - D - Codeforces   D. Range and Partition  time limit per test: 2 second ...

  6. C. Anton and Making Potions 贪心 + 二分

    http://codeforces.com/contest/734/problem/C 因为有两种操作,那么可以这样考虑, 1.都不执行,就是开始的答案是n * x 2.先执行第一个操作,然后就会得到 ...

  7. LightOj1383 - Underwater Snipers(贪心 + 二分)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1383 题意:在平面图中,有一条河,用直线y=k表示,河上面(y>k)的都是敌方区 ...

  8. Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes 贪心/二分

    C. GukiZ hates Boxes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/ ...

  9. UVA 714 Copying Books 最大值最小化问题 (贪心 + 二分)

      Copying Books  Before the invention of book-printing, it was very hard to make a copy of a book. A ...

随机推荐

  1. Python压缩及解压文件

    Zip压缩 #-*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import zipfile #加载模块 # 压缩 z = zipf ...

  2. [Python] Argparse module

    he recommended command-line parsing module in the Python standard library 1. Basic import argparse p ...

  3. shell基本语法和执行

    执行脚本: 编写一个简单的脚本test.sh: #! /bin/sh cd .. ls Shell脚本中用#表示注释,相当于C语言的//注释.但如果#位于第一行开头,并且是#!(称为Shebang)则 ...

  4. 关于网格比较工具metro使用的几点注意事项

    Metro作为一个非常好用的简化网格比较工具,在科研界几乎算是标准了.不过很多比较牛的作者会使用自己设计的一些比较算法,但是如果metro够用了也就不必那么麻烦了,毕竟Metro使用的方法还算是很成熟 ...

  5. Make 命令教程(转载)

    代码变成可执行文件,叫做编译(compile):先编译这个,还是先编译那个(即编译的安排),叫做构建(build). Make是最常用的构建工具,诞生于1977年,主要用于C语言的项目.但是实际上 , ...

  6. /etc/rc5.d/s991local: line25: eject:command not found错误

      使用虚拟机安装centos出现错误,原因是我使用的镜像是最小级别的,没有图形化界面,只有终端窗口 有人用vmware安装minimal centos报错/etc/rc5.d/s99local : ...

  7. boxing & unboxing

    [boxing & unboxing] Boxing is the process of converting a value type to the type object or to an ...

  8. SaltStack 的插件特性

    :first-child { margin-top: 0; } blockquote > :last-child { margin-bottom: 0; } img { border: 0; m ...

  9. memcache分布式的高速缓存系统

    http://baike.baidu.com/link?url=8v9IdWg0i_ptrTfz0APh32-SbvNUAWvXrcZM5vuJ8BrjCR2oylrieOXJ3vkSuRAq3kQV ...

  10. spring bean单例注入与用单例模式通过class.getinstance()区别?

    1.action的某个方法中,用以下代码获得redis单例实例 RedisDelegate redisDelegate = RedisDelegate.getInstance(); redisDele ...