codeforces VK cup 2016-round 1 D.Bear and Contribution
题意大概就是有n个数字,要使至少有k个相同,可以花费b使一个数+5,可以花费c使一个数+1,求最小花费。
要对齐的数肯定是在[v,v+4]之间,所以分别枚举模为0~4的情况就可以了。
排序一下,然后化绝对为相对
例如有 3 6 8 14这4个数,模4,
耗费分别为c+2b 3c+b c+b 0
可以-2b(移动到14时=2*5+4,倍率2)变成c 3c-b c-b -2b
就是说每次都取倍率然后减其花费压入优先队列,若元素数量大于k就弹出最大的那个就可以了
/*没时间自己写个就把其他人的题解搞来了。。。*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <vector>
#include <string>
#include <queue>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <ctime>
using namespace std;
typedef pair<int, int> pii;
typedef long long ull;
typedef long long ll;
typedef vector<int> vi;
#define xx first
#define yy second
#define rep(i, a, n) for (int i = a; i < n; i++)
#define sa(n) scanf("%d", &(n))
#define vep(c) for(decltype((c).begin()) it = (c).begin(); it != (c).end(); it++)
const int mod = int(1e9) + , INF = 0x3fffffff, maxn = 1e5 + ; //ll que[maxn * 4];
int ct[maxn * ]; //小根堆仿函数
class cmp
{
public:
bool operator()(const ll a, const ll b) {
return a > b;
}
}; int main(void) {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
int n, k, b, c;
while (cin >> n >> k >> b >> c) {
rep (i, , n) sa(ct[i]), ct[i] += 1e9;
sort(ct, ct + n);
ll ans = 1ll << ;
if (c * <= b) {
ll sum = ;
for (int i = ; i < n; i++) {
sum += ct[i];
if (i >= k - ) {
ans = min(ans, ((ll)ct[i] * k - sum) * c);
sum -= ct[i - k + ];
}
}
} else {
rep (md, , ) {
ll sum = ;
//int head = 0, tail = 0;
priority_queue<ll, vector<ll>, cmp> que;
rep (i, , n) {
ll cc = (md + - ct[i] % ) % ;
ll bb = (ct[i] + cc) / ;
//等效处理之后的值.
ll cost = bb * b - cc * c;
sum += cost;
// while (head == tail || que[tail - 1] > cost) que[tail++] = cost;
que.push(cost); if (i >= k - ) {
ans = min(ans, (bb * k * b - sum));
sum -= que.top();
que.pop();
}
}
}
}
cout << ans << endl;
} return ;
}
o(n)的解法?没有啦
codeforces VK cup 2016-round 1 D.Bear and Contribution的更多相关文章
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C. Bear and Colors 暴力
C. Bear and Colors 题目连接: http://www.codeforces.com/contest/673/problem/C Description Bear Limak has ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题
A. Bear and Game 题目连接: http://www.codeforces.com/contest/673/problem/A Description Bear Limak likes ...
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) B - Bear and Friendship Condition 水题
B. Bear and Friendship Condition 题目连接: http://codeforces.com/contest/791/problem/B Description Bear ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) E. Bear and Contribution 单调队列
E. Bear and Contribution 题目连接: http://www.codeforces.com/contest/658/problem/E Description Codeforce ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths 构造
D. Bear and Two Paths 题目连接: http://www.codeforces.com/contest/673/problem/D Description Bearland has ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D Bear and Two Paths
题目链接: http://codeforces.com/contest/673/problem/D 题意: 给四个不同点a,b,c,d,求是否能构造出两条哈密顿通路,一条a到b,一条c到d. 题解: ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors
题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)只有A题和B题
连接在这里,->点击<- A. Bear and Game time limit per test 2 seconds memory limit per test 256 megabyte ...
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C. Bear and Different Names 贪心
C. Bear and Different Names 题目连接: http://codeforces.com/contest/791/problem/C Description In the arm ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B. Problems for Round 水题
B. Problems for Round 题目连接: http://www.codeforces.com/contest/673/problem/B Description There are n ...
随机推荐
- Cocos2d-x 3.4环境安装
电脑系统window7 32位 1.首先从官网下载cocos2d-x并解压 http://cn.cocos2d-x.org/download/ 解压后的文件夹中有一个setup.py,双击运行.需要安 ...
- buddy算法
buddy算法是用来做内存管理的经典算法,目的是为了解决内存的外碎片.避免外碎片的方法有两种: 1,利用分页单元把一组非连续的空闲页框映射到非连续的线性地址区间. 2,开发适当的技术来记录现存的空闲连 ...
- Mysql5.5命令行修改密码
今天下载了mysql5.5.45免安装版,配置好之后发现mysql默认是没有设置密码的,也就是密码为空. 如果是本机作开发测试用,有无密码倒也无所谓,不过发布在服务器上没有密码肯定是不行的,那就需要设 ...
- javascript:算法之数组去重
一 /*******************************111111111***********************************/ /*1,最好数组去重方法,利用json的 ...
- 安装Arch Linux
参考自:https://wiki.archlinux.org/index.php/Main_Page_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87) 用fdisk建立分区 ...
- [IT新应用]如何用好搜索引擎学习英语
用谷歌可以学习英语,用必应也可以的. 输入如下地址:global.bing.com,如果是中文界面,就单击顶部右侧“Switch to Bing in English”. 这个界面有很多英文原版的时事 ...
- python随机服务器的双线出口ip发送邮件
#-*- coding:utf-8 -*-import smtplibimport sysimport random import socketfrom email.mime.text import ...
- PHP 判断客户端是IOS还是Android
<?php if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad ...
- NSMutableAttributedString 富文本的使用
//富文本的使用 UILabel *testLabel = [[UILabel alloc]initWithFrame:CGRectMake(, , , )]; testLabel.backgroun ...
- lc.exe已退出代码为1
1.把项目文件夹下Properties文件夹下的licenses.licx文件删除,重新编译即可: 2.文本方式打开*.csproj文件,在文件中查找licenses.licx字样,删除对应节点. 之 ...