Codeforces Round #432 (Div. 1): B. Arpa and a list of numbers
来源:互联网 发布:php print echo 区别 编辑:程序博客网 时间:2024/05/21 09:32
Arpa has found a list containing n numbers. He calls a list bad if and only if it is not empty and gcd (see notes section for more information) of numbers in the list is 1.
Arpa can perform two types of operations:
- Choose a number and delete it with cost x.
- Choose a number and increase it by 1 with cost y.
Arpa can apply these operations to as many numbers as he wishes, and he is allowed to apply the second operation arbitrarily many times on the same number.
Help Arpa to find the minimum possible cost to make the list good.
First line contains three integers n, x and y (1 ≤ n ≤ 5·105, 1 ≤ x, y ≤ 109) — the number of elements in the list and the integers x and y.
Second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the elements of the list.
Print a single integer: the minimum possible cost to make the list good.
4 23 171 17 17 16
40
10 6 2100 49 71 73 66 96 8 60 41 63
10
题意:
给你n个数,你有两个操作:
①将某个数删掉,消耗为x
②将某个数+1,消耗为y,这个操作可以对某个数多次使用
而你的目的是让最后n个数的Gcd不为1,求最小消耗
题解:
对于所有数求前缀和,cnt[i]表示小于等于i的数有多少个,pri[i]表示小于等于i的数之和
暴力Gcd,然后枚举倍数,判断所有的数是删掉更划算还是不停加1更划算
#include<stdio.h>#include<algorithm>using namespace std;#define LL long longLL cnt[2000025], pre[2000025];int main(void){LL temp, x, y, ans;int n, i, c, t, d, st;scanf("%d%lld%lld", &n, &x, &y);for(i=1;i<=n;i++){scanf("%d", &t);cnt[t] ++;pre[t] += t;}ans = x*n;c = x/y;for(i=1;i<=2000005;i++){cnt[i] += cnt[i-1];pre[i] += pre[i-1];}for(d=2;d<=1000000;d++){temp = 0;for(i=d;i<2000005;i+=d){if(i-c>i-d+1)temp += (cnt[i-c-1]-cnt[i-d])*x;st = max(i-c, i-d+1);temp += ((cnt[i-1]-cnt[st-1])*i-(pre[i-1]-pre[st-1]))*y;}ans = min(ans, temp);}printf("%lld\n", ans);return 0;}
- Codeforces Round #432 (Div. 1): B. Arpa and a list of numbers
- Codeforces Round #432 (Div. 1) B. Arpa and a list of numbers
- Codeforces Round #432 B. Arpa and a list of numbers
- Codeforces Round #432 (Div. 2) D 850B Arpa and a list of numbers(gcd 枚举)
- Codeforces Codeforces Round #432 (Div. 2 D ) Arpa and a list of numbers 爆搜+剪枝
- Codeforces Codeforces Round #432 (Div. 2 D ) Arpa and a list of numbers
- Codeforces Round #432 (Div. 2) D. Arpa and a list of numbers E. Arpa and a game with Mojtaba
- 解题报告:Codeforces Round #432 (Div. 2) D. Arpa and a list of numbers 暴力
- Codeforces 851D Arpa and a list of numbers Round #432 (Div. 2
- codeforces 850B Arpa and a list of numbers
- Codeforces Round #432 -思维&素数筛魔改-D-Arpa and a list of numbers
- Codeforces 432 Div. 2-D-Arpa and a list of numbers(枚举倍数求GCD)
- codeforces 580B Arpa and a list of numbers 前缀和+思维+分块 (调和级数)
- Codeforces 851D. Arpa and a list of numbers
- CF850B-Arpa and a list of numbers
- CF_850B Arpa and a list of numbers
- Codeforces Round #432 Div. 1 C. Arpa and a game with Mojtaba
- codeforces 851 D. Arpa and a list of numbers(前缀和+bruteforce)
- android recovery ui相关
- SpringMVC整合Redis实例
- 算法笔记:树和二叉树基础
- 使用weex,开发美食app之vue页面实现
- idea 创建dubbo服务 jar包形式
- Codeforces Round #432 (Div. 1): B. Arpa and a list of numbers
- Python中len()和range()函数
- 拨开字符编码的迷雾--字符编码转换
- 机器学习五大流派,九种常见算法优点场景举例
- css常用效果总结
- DOS黑窗口被选定导致tomcat项目访问不到
- composer windows安装,使用新手入门
- 剑指Offer_面试题41_和为s的两个数字 VS 和为s的连续正数序列
- RxTools一款强大实用的工具类集合