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 ...
随机推荐
- 使用Fiddler的X5S插件查找XSS漏洞
OWASP top 10的安全威胁中的CrossSite Scripting(跨站脚本攻击),允许攻击者通过浏览器往网站注入恶意脚本.这种漏洞经常出现在web应用中需要用户输入的地方,如果网站有XSS ...
- Ubuntu 12.04 系统安装极点五笔输入法
习惯用五笔了,在Ubuntu下安装了下五笔: 下面就实际操作,安装极点五笔输入法! 在终端中执行如下命令: sudo wget http://www.xiit.cn/wp-content/upload ...
- jquery_DOM操作
DOM操作:DOM Core(核心),HTML_DOM,CSS_DOM CSS_DOM操作: css()获取或添加样式 opacity()透明设置 height()高度值 width()宽度 offs ...
- chineseChess
最近学习了chineseChess的Qt实现,把一些东西总结一下: 实现功能: 1.人人对战 2.人机对战 3.网络版 一.基础性工作:(人人对战) 1.棋盘和棋子的绘制(QPinter,drawLi ...
- Centos7 创建个文件 thread 怪现象
我在~下创建个目录thread, 然后写了个程序, 再执行, 提示需要权限, 之后我重命名下文件的名字, 重新编译下, 就可以正常执行了.
- EmguCV 简单图形绘制
一.圆 public static void cvCircle( IntPtr img, System.Drawing.Point center, //Center of the circle int ...
- 使用本地phpmyadmin管理远程数据库
使用放下挺简单的,因为某些业务需求,phpmyadmin不让放在网站服务器上,所以放在本地可以方便管理远程数据库 点击下载会下载一个 config.inc.php 吧这个文件放在phpmyadmin ...
- Linux搭建QT环境笔记
*** [../../../../lib/libQtWebKit.so.4.7.4] Error 1make[1]: Leaving directory `/home/cloverbox/qt-eve ...
- MEMORY Storage Engine MEMORY Tables TEMPORARY TABLE max_heap_table_size
http://dev.mysql.com/doc/refman/5.7/en/create-table.html You can use the TEMPORARY keyword when crea ...
- Mac更换Sublime Text程序图标
更换方法: 下载.icns格式一个图标.http://www.easyicon.net/language.en/iconsearch/sublime/ 终端执行:open /Applications/ ...