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 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...
随机推荐
- quartz-job实现定时任务配置
使用quartz开源调度框架,写服务实现在一些指定场景发送特定短信,创建一个实现org.quartz.Job接口的java类.Job接口包含唯一的方法: public void execute(Job ...
- 计算概论(A)/基础编程练习1(8题)/8:与7无关的数
#include<stdio.h> int main() { ; // n < 100 scanf("%d", &n); // 循环遍历判断 再进行平方和 ...
- SNMP学习笔记之SNMP树形结构介绍
Basic command of SNMP: GET: The GET operation is a request sent by the manager to the managed device ...
- Linux学习笔记之Linux Centos关闭防火墙
# Centos6.x /etc/init.d/iptables stop chkconfig iptables off sed -i 's/SELINUX=enforcing/SELINUX=dis ...
- 重启eclips后启动项目出现监听文件找不到
重启eclips后启动项目出现监听文件找不到 问题: 重启eclips后启动项目出现Error configuring application listener of class com.thinkg ...
- Python3基础 file open 打开txt文件并打印出全文
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- ExtJS使用入门
extjs是基于 yui 由 jack slocum开发, sencha是他们的公司, sencha是由三个项目合并起来的开源项目: ExtJS, jqTouch, Raphael(拉斐尔, 圣经中的 ...
- Trailing Zeroes (III) (二分)题解
You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in d ...
- BZOJ1355: [Baltic2009]Radio Transmission KMP
Description 给你一个字符串,它是由某个字符串不断自我连接形成的. 但是这个字符串是不确定的,现在只想知道它的最短长度是多少. Input 第一行给出字符串的长度,1 < L ≤ 1, ...
- C#学习笔记(七):结构体、数组、冒泡排序和调试
结构体 结构体不能重写默认无参构造函数 一位数组 using System; using System.Collections.Generic; using System.Linq; using Sy ...