Skills CodeForces - 614D (贪心)
大意: $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 (贪心)的更多相关文章
- codeforces 613B B. Skills(枚举+二分+贪心)
题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- [CodeForces - 614D] D - Skills
D - Skills Lesha plays the recently published new version of the legendary game hacknet. In this ver ...
- CodeForces 614D Skills
排序+枚举+二分 最大的那些变成A,小的那部分提高最小值 #include<cstdio> #include<cstring> #include<cmath> #i ...
- CodeForces - 893D 贪心
http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...
- 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 ...
- 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 ...
- 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 ...
- C - Ordering Pizza CodeForces - 867C 贪心 经典
C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...
- Codeforces 570C 贪心
题目:http://codeforces.com/contest/570/problem/C 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...
随机推荐
- Python 运算符与基本数据类型
一.运算符 1.算数运算: 2.比较运算: 3.赋值运算: 4.逻辑运算: 5.成员运算: 二.基本数据类型 1.空(None) 表示该值是一个空对象,空值是Python里一个特殊的值,用None表示 ...
- 如何使用Unity制作虚拟导览(一)
https://www.cnblogs.com/yangyisen/p/5108289.html Unity用来制作游戏已经是目前市场上的一个发展趋势,而且有越来越多的公司与开发者不断的加入,那么Un ...
- mysql 触发器 trigger用法 three (稍微复杂的)
MySQL包含对触发器的支持.触发器是一种与表操作有关的数据库对象,当触发器所在表上出现指定事件时,将调用该对象,即表的操作事件触发表上的触发器的执行. 创建触发器 在MySQL中,创建触发器语法如下 ...
- SACD ISO镜像中提取DSDIFF(DFF)、DSF文件
听语音 | 浏览:5620 | 更新:2015-08-25 11:46 | 标签:硬件 1 2 3 4 5 分步阅读 现在有一种比较流行的无损音乐传输介质是SACD ...
- Java HSSFworkbook,XSSFworkbook,SXSSFworkbook区别简述
Java HSSFworkbook,XSSFworkbook,SXSSFworkbook区别简述 一.HSSFworkbook,XSSFworkbook,SXSSFworkbook区别简述 用Java ...
- python 线程 进程 协程 学习
转载自大神博客:http://www.cnblogs.com/aylin/p/5601969.html 仅供学习使用···· python 线程与进程简介 进程与线程的历史 我们都知道计算机是由硬件和 ...
- IPMB接口协议总结
IPMB接口协议总结 IPMB,智能平台管理总线, 是ATCA(Advanced Telecom Computing Architecture)先进的电信计算平台的各FRU背板通讯的两组冗余I2C总线 ...
- 在awk中通过system调用sql语句来说明引号的使用
一个实际应用例子: 在awk中,通过system调用连接数据库并作select操作,select语句中where条件来自于一个文件(file)的第一个域($1). $ cat file ... ... ...
- 数据结构-队列(3)-使用Java内置队列
大多数流行语言都提供内置的队列库,因此您无需重新发明轮子. 如前所述,队列有两个重要的操作,入队 enqueue 和出队 dequeue. 此外,我们应该能够获得队列中的第一个元素,因为应该首先处理它 ...
- 设置控件如ImageButton可见与否
继承view的控件有三种ui属性: 1.setVisibility(View.Gone); 不可见,不占有空间 2.setVisibility(View.VISIBLE); 可见 3.setVisib ...