链接

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

$cnt_{mx}$为满分的科目数, $mi$为最低分, $cf$, $cm$为给定系数

暴力枚举达到满分的科目数, 再二分答案求出最低分的最大值, 复杂度是$O(nlognlogmx)$

似乎可以双指针省去二分答案的log, 不过懒得写了..

#include <iostream>
#include <algorithm>
#include <cstdio>
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii; const int N = 4e5+10, INF = 0x3f3f3f3f;
int n, mx, cf, cm;
pii a[N];
ll m, s1[N], s2[N];
int f[N]; int chk(int cnt, int x) {
int t = lower_bound(a+1,a+1+n,pii(x,0))-a-1;
ll c = (ll)t*x-s1[t];
if (c>m) return 0;
if (t+cnt<=n) return c+s2[n-cnt+1]<=m;
c += s2[t+1], cnt -= n-t;
c += (ll)(mx-x)*cnt;
return c<=m;
} int main() {
scanf("%d%d%d%d%lld", &n, &mx, &cf, &cm, &m);
REP(i,1,n) scanf("%d", &a[i].x),a[i].y=i;
sort(a+1,a+1+n);
REP(i,1,n) s1[i]=s1[i-1]+a[i].x;
PER(i,1,n) s2[i]=s2[i+1]+mx-a[i].x;
ll ans = 0;
int cnt=-1, mi;
REP(i,0,n) {
if (s2[n-i+1]>m) break;
int l=0, r=mx, t=-1;
while (l<=r) {
int mid=(l+r)/2;
if (chk(i,mid)) t=mid,l=mid+1;
else r=mid-1;
}
if ((ll)i*cf+(ll)t*cm<=ans) continue;
ans = (ll)i*cf+(ll)t*cm;
cnt = i, mi = t;
}
if (cnt>=0) {
REP(i,1,n) a[i].x=max(a[i].x,mi);
PER(i,1,n) if (cnt) --cnt,a[i].x=mx;
}
REP(i,1,n) f[a[i].y]=a[i].x;
printf("%lld\n", ans);
REP(i,1,n) printf("%d ",f[i]);
puts("");
}

Skills CodeForces - 614D (贪心)的更多相关文章

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

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

  2. [CodeForces - 614D] D - Skills

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

  3. CodeForces 614D Skills

    排序+枚举+二分 最大的那些变成A,小的那部分提高最小值 #include<cstdio> #include<cstring> #include<cmath> #i ...

  4. CodeForces - 893D 贪心

    http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...

  5. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  6. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心

    Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...

  7. CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作

    题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...

  8. C - Ordering Pizza CodeForces - 867C 贪心 经典

    C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...

  9. Codeforces 570C 贪心

    题目:http://codeforces.com/contest/570/problem/C 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...

随机推荐

  1. 面试题之一(Spring和堆栈和逻辑运算符)

    1.&和&&区别? 都是逻辑运算符,都是判断两边同时为真,否则为假:但&&当第一个为假时,后面就不执行,而&则还是要继续执行,直至结束: ——————— ...

  2. Putty Technical Note

    转载自:http://libai.math.ncu.edu.tw/bcc16/6/putty/puttyt.html Terminal panel Terminal 面板可調整 PuTTY 對於模擬終 ...

  3. Python3: Windows系统上同时安装Python2和Python3

    Python3: Windows系统上同时安装Python2和Python3 为什么要同时安装Python2和Python3环境呢? 因为一些库只支持Python2或者Python3; 在同一台电脑上 ...

  4. C++面向对象高级开发课程(第二周)

    1. 类中含有指针—— class with pointer member(s) ——的情况经常发生,典型的有:string 类. 2. STL中的 string 类太复杂,copy on write ...

  5. ms11_050漏洞攻击

    ms11_050漏洞攻击 开启msfconsole 查看针对MS11_050漏洞的攻击模块 进入模块 查看该模块的具体信息 设置paylaods 查看具体参数设置 设置其相关参数 攻击 ie浏览器发生 ...

  6. 开源项目托管GitHub

    工具:本地HelloWorld源项目 msysgit(Windows) 实验步骤:一.在GitHub新建托管项目 在http://github.com注册账号20159214-sunnan. 完成注册 ...

  7. 关于 Local feature 和 Global feature 的组合

     关于  Local feature 和 Global feature 的组合     1.全局上下文建模:  

  8. Java异常类复习总结

    个人理解先行: 异常类是当在程序出现问题时抛出的一个警告.提示你程序设计或者代码有存在错误的地方. 异常类和Error都继承自Throwable, Throwable继承自Object类. Runti ...

  9. FOJ-1058-粗心的物理学家

    题目:粗心的物理学家 代码: #include<stdlib.h> #include<iostream> #include<cstdio> using namesp ...

  10. ros 使用命令测试topic

    发布话题 $ rostopic pub -r /chatter std_msgs/String "test" 输出数据: $ rostopic echo /chatter data ...