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. css和javascript代码写在页面中的位置说明

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. jquery简单使用入门

    <!DOCTYPE html> <html> <head> <title>jquery</title> <meta charset=& ...

  3. python连接kafka生产者,消费者脚本

    # -*- coding: utf-8 -*- ''''' 使用kafka-Python 1.3.3模块 # pip install kafka==1.3.5 # pip install kafka- ...

  4. java按照关键字指定的key删除redis(支持模糊删除)

    pom依赖: <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</a ...

  5. Json 文件中value的基本类型

    在Json中,value的类型只能是以下几种: 1.字符串 2.数字 3.true 或者 false (注意,和字符串不同,没有双引号包裹) 4.null

  6. css之坑

    1.background-size要放在background后边才会生效. 2.隐藏滚动条,内容可以滑动 body::-webkit-scrollbar { display: none /* 隐藏滚动 ...

  7. 分布式通讯架构RPC简单实现

    什么是RPC: RPC(Remote Procedure Call,远程过程调用),一般用来实现部署在不同机器上的系统之间的方法调用,使得程序能够像访问本地系统资源一样,通过网络传输去访问远端系统资源 ...

  8. 【mongo】centos6.9安装mongo2.6.3

    参考:http://www.haorooms.com/post/3m 注意:centos6上就不要装mongo3了,容易出错. 1. 下载 curl -O http://downloads.mongo ...

  9. html 基本指令

    命令: <pre> </pre> 格式化输出 <ol></ol> 有序 HTML 列表:示例: <pre> here is outout & ...

  10. java实现 排序算法(鸡尾酒排序&选择排序&插入排序&二分插入排序)

    1.鸡尾酒排序算法 源程序代码: package com.SuanFa; public class Cocktial {    public static void main(String[] arg ...