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的更多相关文章

  1. codeforces 657C - Bear and Contribution [想法题]

    题目链接: http://codeforces.com/problemset/problem/657/C ----------------------------------------------- ...

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

  3. Codeforces 385C Bear and Prime Numbers

    题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...

  4. Codeforces 385B Bear and Strings

    题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...

  5. Codeforces 680D Bear and Tower of Cubes 贪心 DFS

    链接 Codeforces 680D Bear and Tower of Cubes 题意 求一个不超过 \(m\) 的最大体积 \(X\), 每次选一个最大的 \(x\) 使得 \(x^3\) 不超 ...

  6. Codeforces 385C Bear and Prime Numbers(素数预处理)

    Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...

  7. [Codeforces 639F] Bear and Chemistry (Tarjan+虚树)(有详细注释)

    [Codeforces 639F] Bear and Chemistry(Tarjan+虚树) 题面 给出一个n个点,m条边的无向图(不保证连通,可能有自环和重边),有q次询问,每次询问给出p个点和q ...

  8. codeforces VK cup 2016-round 1 D.Bear and Contribution

    题意大概就是有n个数字,要使至少有k个相同,可以花费b使一个数+5,可以花费c使一个数+1,求最小花费. 要对齐的数肯定是在[v,v+4]之间,所以分别枚举模为0~4的情况就可以了. 排序一下,然后化 ...

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

随机推荐

  1. es2015箭头函数的this

    摘自https://www.cnblogs.com/chenxygx/p/6509564.html,谢谢博主的分享!

  2. linux-history显示历史命令执行时间

    vim  ~/.bashrc 或者 ~/.bash_profile 增加:export HISTTIMEFORMAT="%F %T  " 一次会话的话先执行 然后使用history ...

  3. hadoop 透明加密

    hadoop 透明加密 hadoop 透明加密 kms transparent 2015年04月09日 18:12:20 糖糖_ 阅读数:12248 标签: transparenthadoop kms ...

  4. f11 全屏

    function fullScreen() { var el = document.documentElement; var rfs = el.requestFullScreen || el.webk ...

  5. 金九银十中,看看这31道Android面试题

    阅读目录 1.如何对 Android 应用进行性能分析 2.什么情况下会导致内存泄露 3.如何避免 OOM 异常 4.Android 中如何捕获未捕获的异常 5.ANR 是什么?怎样避免和解决 ANR ...

  6. Confluence 6 为空白空间编辑默认主页

    希望编辑默认(空白)空间内容模板: 在屏幕的右上角单击 控制台按钮 ,然后选择 General Configuration 链接. 在左侧的面板中选择 全局模板和蓝图(Global Templates ...

  7. Confluence 6 用户宏示例 - Color and Size

    这个示例定义了如何向你宏中传递参数.我们将会创建一个字体样式宏,在这个宏中有 2 个参数,允许用户在这 2 个参数中指定宏中包含的字体的颜色大小. Macro name stylish Visibil ...

  8. BIgnum类的程序提交

    日期:2018.7.19 星期四 博客期:002 这之前赶着做一个单机游戏的修改器忘了时间,不好意思啊!今天我就把Bignum类的源代码发出来,文件的话,我不知道怎样发,待我好好研究研究这个网站哈!因 ...

  9. usrp使用

    首先打开linux 输入uhd_find_divice gqrx

  10. 1873: This offer(zzuli)

    题目描述 话说WX入职已经有一个多月了,公司boss突然扔给他了一个问题,如果解决不了的话就会被开除掉 - -#,情急之下他只能来请教你了,boss给了他N个不大于100的数,现在wx需要将这N个数通 ...