链接

大意: $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. mysql日志文件目录

    默认情况下mysql的二进制日志文件保存在默认的数据目录data下,如:/usr/local/mysql/data 修改日志保存目录(/backup/mysqlbinlog/mysql-bin)的话: ...

  2. oracle中使用函数控制过程是否执行(结合job使用)

    oracle中使用函数控制过程是否执行(结合job使用时候,循环时间不好写的时候,可以此种方法比较方便) CREATE OR REPLACE FUNCTION wsbs_pk_date_validat ...

  3. MySQL Crash Course #19# Chapter 27. Globalization and Localization

    Globalization and Localization When discussing multiple languages and characters sets, you will run ...

  4. 简单的HTML5 canvas游戏工作原理

    HTML5已经不是一个新名词.它看上去很cool,有很多feature,大多数人普遍看好它的发展.对于我来说,最感兴趣的是它的canvas标签,可以结合Javascript来绘制游戏画面. 我们可以在 ...

  5. QtQuickcontrols2控件使用参考

    随着Qt的版本升级,其自带的controls控件库也不断升级,目前已经到了2.3的版本.本文通过解读Qt自带的gallery例程,说明新版本controls控件库的相关特性.其具体位置于: 因为相关的 ...

  6. 使用dll,将image库开放出去

    这是很经典的想法了,但是如何来做,不经过摸索不知道细节.   最简单: dll处   #include "stdafx.h"   #ifdef _DEBUG #define new ...

  7. 安装PyInstaller打包python

    安装PyInstaller 对于那些网络比较稳定,能够流畅使用pip源地址的用户,直接下面的命令就可以搞定: pip install pyinstaller 通常我们会下载源码包,然后进入包目录,执行 ...

  8. 搭建最新版本的Android开发环境

    只为成功找方法,不为失败找借口! Android开发学习总结(一)——搭建最新版本的Android开发环境 最近由于工作中要负责开发一款Android的App,之前都是做JavaWeb的开发,Andr ...

  9. P4113 [HEOI2012]采花 (莫队TLE)

    思路 update 11.2 树状数组AC 本题莫队过不去,会TLE ----------------------- 但也是个不错的莫队练手题 ------------------------ 毕竟C ...

  10. HDU 6148 Valley Numer (数位DP)题解

    思路: 只要把status那里写清楚就没什么难度T^T,当然还要考虑前导零! 代码: #include<cstdio> #include<cstring> #include&l ...