题意大概就是有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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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. 题解: ...

  7. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors

    题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. ...

  8. 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 ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. 集中式版本控制VS分布式版本控制

    CVS及SVN都是集中式的版本控制系统,而Git是分布式版本控制系统,集中式和分布式版本控制系统有什么区别呢? 集中式版本控制系统,版本库是集中存放在中央服务器的,而干活的时候,用的都是自己的电脑,所 ...

  2. java中的反射

    1.何为java反射机制: 在运行过程中,对于任意一个类都能够知道这个类的属性和方法:对于任意一个对象都能调用其属性和方法:这种动态获取信息和动态调用方法 就称为java反射 2.获取Class对象的 ...

  3. 怎么启动或停止mysql服务

    在linux下,  启动mysql用 service mysql start   停止用 service mysql stop 在windows下, 启动用 net start mysql    停止 ...

  4. 【iCore3 双核心板】iCore3封装库及使用说明V1.0

    iCore3封装库及使用说明下载链接: http://pan.baidu.com/s/1pLq23Qb iCore3 购买链接: https://item.taobao.com/item.htm?id ...

  5. Codeforces Round #350 (Div. 2) D2 二分

    五一期间和然然打的团队赛..那时候用然然的号打一场掉一场...七出四..D1是个数据规模较小的题 写了一个暴力过了 面对数据如此大的D2无可奈何 现在回来看 一下子就知道解法了 二分就可以 二分能做多 ...

  6. C# 拷贝数组的几种方法

    已知数组如下: int[] array = { 1, 5, 9, 3, 7, 2, 8 ,6, 4}; (1).引用复制,易引起错误,不推荐 int[] copy = array; (2).遍历拷贝 ...

  7. shell读取文件每行,并执行命令

    #!/bin/bash while read line do $line & done < /path/filename

  8. js串讲回顾

    注:1.xx.nextSibling.css.xxx->xx的下一个元素的css样式;2. window.opener.document.getElementById("cms&quo ...

  9. (转)python爬取拉勾网信息

    学习Python也有一段时间了,各种理论知识大体上也算略知一二了,今天就进入实战演练:通过Python来编写一个拉勾网薪资调查的小爬虫. 第一步:分析网站的请求过程 我们在查看拉勾网上的招聘信息的时候 ...

  10. pycharm 单元测试失败 not found while handling absolute import

    pycharm 单元测试运行错误 RuntimeWarning: Parent module 'tests' not found while handling absolute import impo ...