Codeforces 639D Bear and Contribution
对于对于5余数为, 0, 1, 2, 3, 4的分别处理一次, 用优先队列贪心。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, k, b, c, t[N];
PII a[N];
LL ans = INF; LL cnt = ;
priority_queue<PLI> que; LL solve(PII *a, LL b, LL c) {
while(!que.empty()) que.pop();
cnt = ;
LL ans = INF, ret = ;
for(int i = ; i <= k; i++) {
ret += a[i].se * c;
ret += (a[i].fi - a[i - ].fi) * cnt * b;
que.push(mk(c * a[i].se + (a[].fi - a[i].fi) * b, i));
cnt++;
}
ans = min(ans, ret);
for(int i = k + ; i <= n; i++) {
int p = que.top().se; que.pop(); cnt--;
ret -= a[p].se * c;
ret -= (a[i - ].fi - a[p].fi) * b;
ret += (a[i].fi - a[i - ].fi) * cnt * b;
ret += a[i].se * c;
que.push(mk(c * a[i].se + (a[].fi - a[i].fi) * b, i));
cnt++;
ans = min(ans, ret);
}
return ans;
} int main() {
scanf("%d%d%d%d", &n, &k, &b, &c);
for(int i = ; i <= n; i++) scanf("%d", &t[i]), t[i] += ;
sort(t + , t + + n);
for(int i = ; i <= n; i++) a[i].fi = t[i], a[i].se = ;
ans = min(ans, solve(a, c, ));
for(int j = ; j < ; j++) {
for(int i = ; i <= n; i++) {
a[i].se = ((j - (t[i] % )) + ) % ;
a[i].fi = (t[i] + a[i].se) / ;
}
ans = min(ans, solve(a, b, c));
}
printf("%lld\n", ans);
return ;
} /*
*/
Codeforces 639D Bear and Contribution的更多相关文章
- codeforces 657C - Bear and Contribution [想法题]
题目链接: http://codeforces.com/problemset/problem/657/C ----------------------------------------------- ...
- 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 385C Bear and Prime Numbers
题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...
- Codeforces 385B Bear and Strings
题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...
- Codeforces 680D Bear and Tower of Cubes 贪心 DFS
链接 Codeforces 680D Bear and Tower of Cubes 题意 求一个不超过 \(m\) 的最大体积 \(X\), 每次选一个最大的 \(x\) 使得 \(x^3\) 不超 ...
- Codeforces 385C Bear and Prime Numbers(素数预处理)
Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...
- [Codeforces 639F] Bear and Chemistry (Tarjan+虚树)(有详细注释)
[Codeforces 639F] Bear and Chemistry(Tarjan+虚树) 题面 给出一个n个点,m条边的无向图(不保证连通,可能有自环和重边),有q次询问,每次询问给出p个点和q ...
- codeforces VK cup 2016-round 1 D.Bear and Contribution
题意大概就是有n个数字,要使至少有k个相同,可以花费b使一个数+5,可以花费c使一个数+1,求最小花费. 要对齐的数肯定是在[v,v+4]之间,所以分别枚举模为0~4的情况就可以了. 排序一下,然后化 ...
- Codeforces 791B Bear and Friendship Condition(DFS,有向图)
B. Bear and Friendship Condition time limit per test:1 second memory limit per test:256 megabytes in ...
随机推荐
- 缓存系列之四:redis持久化与redis主从复制
一:redis 虽然是一个内存级别的缓存程序,即redis 是使用内存进行数据的缓存的,但是其可以将内存的数据按照一定的策略保存到硬盘上,从而实现数据持久保存的目的,redis支持两种不同方式的数据持 ...
- 缓存系列之三:redis安装及基本数据类型命令使用
一:Redis是一个开源的key-value存储系统.与Memcached类似,Redis将大部分数据存储在内存中,支持的数据类型包括:字符串.哈希表.链表.集合.有序集合以及基于这些数据类型的相关操 ...
- OpenStack实践系列⑧可视化服务Horizon之Dashboard演示
OpenStack实践系列⑧可视化服务Horizon之Dashboard演示 七.可视化服务Horizon之Dashboard演示 仪表板依赖于功能核心服务,包括身份,图像服务,计算和网络两种(neu ...
- ASP.NET MVC5高级编程 之 模型
1. 为MVC Music Store建模 Models文件夹(右击) --> 添加 --> 类 为类添加对应的属性: public class Album { public virtua ...
- Day8--------------yum软件包管理
1.url三段式:协议.域名.路径 例如:http://wan.360.cn/game 2.本地yum配置: vim /etc/yum.repos.d/local.repo [local] #固定格式 ...
- Confluence 6 布局高级自定义
重载 Velocity 模板 velocity 目录是 Confluence Velocity 模板文件进行搜索时候需要的文件夹.例如,你可以通过将你的 Velocity 文件使用正确的文件名放置到正 ...
- jquery_ajax 跨域
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- SpringBoot捕获全局异常
1.创建GloableExceptionAop类捕获全局异常 package com.cppdy.exception; import org.springframework.web.bind.anno ...
- Android源码分析二 硬件抽象层(HAL)
一 什么是HAL HAL 可定义一个标准接口以供硬件供应商实现,这可让 Android 忽略较低级别的驱动程序实现.借助 HAL,您可以顺利实现相关功能,而不会影响或更改更高级别的系统.HAL 实现会 ...
- C++ 解析Json——jsoncpp(转)
原文:https://www.cnblogs.com/liaocheng/p/4243731.html JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,和 ...