排序+枚举+二分

最大的那些变成A,小的那部分提高最小值

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn=+;
int n;
long long A,cf,cm,m;
struct X
{
long long a;
long long ans;
int id;
} s[maxn];
long long sum[maxn]; bool cmp1(const X&a,const X&b)
{
return a.a<b.a;
} bool cmp2(const X&a,const X&b)
{
return a.id<b.id;
} int main()
{
scanf("%d%lld%lld%lld%lld",&n,&A,&cf,&cm,&m);
for(int i=; i<=n; i++)
{
scanf("%lld",&s[i].a);
s[i].id=i;
s[i].ans=s[i].a;
}
sort(s+,s++n,cmp1);
memset(sum,,sizeof sum);
for(int i=; i<=n; i++) sum[i]=sum[i-]+s[i].a;
int ansPos1=,ansPos2=;
long long Max=-;
long long ave=;
for(int i=; i<=n; i++) //最后i个都变成A
{
long long cost=A*i-(sum[n]-sum[n-i]);//最后i个都变成A需要的费用
if(cost>m) break;// 如果费用超过了m,则结束 cost=m-cost;//剩余的费用
int left=,right=n-i;//二分查找的范围
int pos=;
while(left<=right)
{
int mid=(left+right)/;
if(mid*s[mid].a-sum[mid]<=cost)
{
pos=mid;
left=mid+;
}
else right=mid-;
}
long long q;
if(pos!=) q=min(A,(cost-pos*s[pos].a+sum[pos])/pos+s[pos].a);
else q=A;
if(q*cm+i*cf>Max)
{
Max=q*cm+i*cf;
ansPos1=pos;
ansPos2=i;
ave=q;
}
} for(int i=n;i>=n-ansPos2+;i--) s[i].ans=A;
for(int i=;i<=ansPos1;i++) s[i].ans=ave; printf("%lld\n",Max);
sort(s+,s+n+,cmp2);
for(int i=;i<=n;i++)
{
printf("%lld",s[i].ans);
if(i<n) printf(" ");
else printf("\n");
}
return ;
}

CodeForces 614D Skills的更多相关文章

  1. [CodeForces - 614D] D - Skills

    D - Skills Lesha plays the recently published new version of the legendary game hacknet. In this ver ...

  2. Skills CodeForces - 614D (贪心)

    链接 大意: $n$门课, 第$i$门分数$a_i$, 可以增加共$m$分, 求$cnt_{mx}*cf+mi*cm$的最大值 $cnt_{mx}$为满分的科目数, $mi$为最低分, $cf$, $ ...

  3. 「日常训练」Skills(Codeforce Round #339 Div.2 D)

    题意(CodeForces 614D) 每个人有\(n(n\le 10^5)\)个技能,技能等级都在\([0,10^9]\)的范围,每个技能有一个当前等级,所有技能的最高等级都为A.一个人的力量被记做 ...

  4. Codeforces Round #322 (Div. 2) C. Developing Skills 优先队列

    C. Developing Skills Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  5. Codeforces Round #339 (Div. 1) B. Skills 暴力 二分

    B. Skills 题目连接: http://www.codeforces.com/contest/613/problem/B Description Lesha plays the recently ...

  6. codeforces 581C. Developing Skills 解题报告

    题目链接:http://codeforces.com/problemset/problem/581/C 题目意思:给出 n 个数:a1, a2, ..., an (0 ≤ ai ≤ 100).给出值 ...

  7. codeforces 613B B. Skills(枚举+二分+贪心)

    题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  8. 【CodeForces 613B】Skills

    题 题意 给你n个数,可以花费1使得数字+1,最大加到A,最多花费m.最后,n个数里的最小值为min,为A的有k个,给你cm和cf,求force=min*cm+k*cf 的最大值,和n个数操作后的结果 ...

  9. Skills CodeForces - 613B (双指针)

    大意: $n$门课, 第$i$门分数$a_i$, 可以增加共$m$分, 求$cnt_{mx}*cf+mi*cm$的最大值 $cnt_{mx}$为满分的科目数, $mi$为最低分, $cf$, $cm$ ...

随机推荐

  1. CentOS 7 BIND 搭建

    域名查找顺序 设置 /etc/host.conf 1. bind 安装 $ yum install bind bind-utilsnslookup (name server lookup) 在bind ...

  2. string 转 int,int 转 string

    string str="12345"; int b=atoi(str.c_str()); 可以配合atof,转为double char buf[10]; sprintf(buf,  ...

  3. textarea内容太多, 鼠标点击全部显示

    strRight+="<td bordercolor='#DEDEDE' width='500px' height='50'><div title='"+data ...

  4. http請求瀏覽器的緩存機制

    轉載自:http://kb.cnblogs.com/page/73901/ 流程 当资源第一次被访问的时候,HTTP头部如下 (Request-Line) GET /a.html HTTP/1.1 H ...

  5. JS限制 获取动太ID,播放视频

    JS限制textarea字数 function textdown(e) {textevent = e ; ) { return; } ) { alert("大侠,我手机屏幕小,先输入这么多字 ...

  6. Arch: Configurations

    the original purpose is to show the steps needed to setup i3 in vbox.. easy. alright, it is a bit mi ...

  7. php 日期处理 例子

    <?php date_default_timezone_set('PRC'); //默认时区 echo "今天:",date("Y-m-d",time() ...

  8. Arrays类与Array类探究

    这里所说的Arrays类是util包中的java.util.Arrays,Array是反射包中的java.lang.reflect.Array. 首先介绍Arrays类的常用的静态方法: 1.排序方法 ...

  9. Tiny210编译和烧写u-boot步骤

    当有多个交叉编译器是,不方便设置环境变量时,可以在编译命令中指定交叉编译器,具体如下: make ARCH=arm CROSS_COMPILE=/opt/FriendlyARM/toolschain/ ...

  10. HTML元素分类:块级元素 内联元素和内联块状元素

    在CSS中,html中的标签元素大体被分为三种不同的类型:块状元素.内联元素(又叫行内元素)和内联块状元素. 1,块状元素 常用的块状元素有: <div>.<p>.<h1 ...