题意大概就是有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. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset(可持久化Trie)

    D. Vasiliy's Multiset time limit per test 4 seconds memory limit per test 256 megabytes input standa ...

  2. 基于 ThinkPHP 3.2.3 的页面静态化功能的实现

    PHP 的页面静态化有多种实现方式,比如使用输出缓冲(output buffering),该种方式是把数据缓存在 PHP 的缓冲区(内存)中,下一次取数据时直接从缓冲区中读取数据,从而避免了脚本的编译 ...

  3. hibernate学习(1)——helloworld

    1. 框架体系结构 2. hibernate入门 2.1 ORM框架 Hibernate是一个数据持久化层的ORM框架. Object:对象,java对象,此处特指JavaBean Relationa ...

  4. mysql root 维护

    修改root密码: mysql -uroot -paaamysql> use mysql;mysql> UPDATE user SET password=password("aa ...

  5. go gomail

    package main //cmd: go get gopkg.in/gomail.v1 import ( "gopkg.in/gomail.v1" ) func main() ...

  6. 蓝牙—RFCOMM协议

    RFCOMM是一个简单的协议,其中针对9针RS-232串口仿真附加了部分条款.可支持在两个蓝牙设备之间同时保持高达60路的通信连接.RFCOMM的目的是针对如何在两个不同设备上的应用之间保证一条完整的 ...

  7. QMessageBox

    #include "dialog.h" #include "ui_dialog.h" #include<QMessageBox> Dialog::D ...

  8. bat批处理完成jdk tomcat的安装

    在完成一个web应用项目后,领导要求做一个配置用的批处理文件,能够自动完成jdk的安装,tomcat的安装,web应用的部署,环境变量的注册,tomcat服务的安装和自动启动 参考了网上很多的类似的批 ...

  9. thinkphp多语言设置

    thinkphp多语言设置有点'高大上',为什么说它有点'高大上'呢?因为本人设置了好久才弄好,而本人之所以弄了好久的原因,竟然是因为'开启语言设置必须得先开启初始化系统的行为类',所以,在这里,因为 ...

  10. PHP调用内容DES加密的SOAP接口

    本文以方倍工作室优惠券接口开发为例,介绍PHP下DES加解密及SOAP接口调用的实现过程. 一.基础概念 DES全称为Data Encryption Standard,即数据加密标准,是一种使用密钥加 ...