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. nginx负载均衡优化配置

    针对nginx做负载均衡时其中一台服务器挂掉宕机时响应速度慢的问题解决 nginx会根据预先设置的权重转发请求,若给某一台服务器转发请求时,达到默认超时时间未响应,则再向另一台服务器转发请求. 默认超 ...

  2. python序列(列表,元组,字典)的常用排序

    列表 正向排序 sort() >>> list=[1,6,3,4,5,2] >>> list.sort() >>> list [1, 2, 3, ...

  3. Light OJ 1102

    题意: 给你一个数 N , 求分成 K 个数 (可以为 0 ) 的种数: 思路: 类似 在K个抽屉放入 N 个苹果, 不为0, 就是 在 n-1 个空隙中选 m-1个: 为 0, 就可以先在 K 个抽 ...

  4. Elasticsearch索引别名、Filtered索引别名、Template

    在使用elasticsearch的时候,经常会遇到需要淘汰掉历史数据的场景. 为了方便数据淘汰,并使得数据管理更加灵活,我们经常会以时间为粒度建立索引,例如: 每个月建立一个索引:monthly-20 ...

  5. 移动端触屏滑动touches使用

    代码 var start = { x: 0, y: 0 } var end = { x: 0, y: 0 } document.addEventListener('touchstart', funct ...

  6. [Linux]关于字节序的解析

    剥鸡蛋的故事 <格列佛游记>中记载了两个征战的强国,你不会想到的是,他们打仗竟然和剥鸡蛋的姿势有关. 很多人认为,剥鸡蛋时应该打破鸡蛋较大的一端,这群人被称作“大端(Big endian) ...

  7. http请求在ie中F12查看显示已挂起

    页面有解析和运算工作之后 http新请求在ie中F12查看显示已挂起,http post ,请求返回少量数据

  8. BeautifulSoup解析器的选择

    BeautifulSoup解析器 在我们使用BeautifulSoup的时候,选择怎样的解析器是至关重要的.使用不同的解析器有可能会出现不同的结果! 今天遇到一个坑,在解析某html的时候.使用htm ...

  9. 7)django-示例(cbv)

    CBV(class base view)一个url根据method方式调用相应的方法.method常用有get,post 如果是GET请求,Home类会调用get方法,如果是POST提交数据,则类会调 ...

  10. Python-爬虫-猫眼T100

    目标站点需求分析 涉及的库 from multiprocessing import Poolfrom requests.exceptions import RequestExceptionimport ...