Codeforces #Round 376 F 题解
1 second
256 megabytes
standard input
standard output
Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated.
There are n video cards in the shop, the power of the i-th video card is equal to integer value ai. As Vlad wants to be sure the new game will work he wants to buy not one, but several video cards and unite their powers using the cutting-edge technology. To use this technology one of the cards is chosen as the leading one and other video cards are attached to it as secondary. For this new technology to work it's required that the power of each of the secondary video cards is divisible by the power of the leading video card. In order to achieve that the power of any secondary video card can be reduced to any integer value less or equal than the current power. However, the power of the leading video card should remain unchanged, i.e. it can't be reduced.
Vlad has an infinite amount of money so he can buy any set of video cards. Help him determine which video cards he should buy such that after picking the leading video card and may be reducing some powers of others to make them work together he will get the maximum total value of video power.
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of video cards in the shop.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 200 000) — powers of video cards.
The only line of the output should contain one integer value — the maximum possible total power of video cards working together.
4
3 2 15 9
27
4
8 2 2 7
18
In the first sample, it would be optimal to buy video cards with powers 3, 15 and 9. The video card with power 3 should be chosen as the leading one and all other video cards will be compatible with it. Thus, the total power would be 3 + 15 + 9 = 27. If he buys all the video cards and pick the one with the power 2 as the leading, the powers of all other video cards should be reduced by 1, thus the total power would be 2 + 2 + 14 + 8 = 26, that is less than 27. Please note, that it's not allowed to reduce the power of the leading video card, i.e. one can't get the total power 3 + 1 + 15 + 9 = 28.
In the second sample, the optimal answer is to buy all video cards and pick the one with the power 2 as the leading. The video card with the power 7 needs it power to be reduced down to 6. The total power would be 8 + 2 + 2 + 6 = 18.
————————————分割线————————————
分析:
枚举每个数字,让它成为主视频卡ak,然后枚举倍数 j ,将j介于 ( j - 1 ) * ak<= x < j * ak , 全部减少到 ( j - 1 ) * ak,为了快速的找到这些数,可以使用前缀和优化思想。
例如:
a1为现在的主视频卡,让介于[ a1 * 1 , a1 * 2 ) 减少到a1 , 让介于[ a1 * 2 , a1 * 3 ) 减少到2 * a1 , 依此类推... ...
#include "bits/stdc++.h" using namespace std ;
const int maxN = 3e5 + 1e3 ;
const int INF = ;
typedef long long QAQ ; QAQ Sum[ maxN ] , buc[ maxN ] ; inline int INPUT ( ) {
int x = , f = ; char ch = getchar ( ) ;
while ( ch < '' || '' < ch ) { if ( ch == '-' ) f = - ; ch = getchar ( ) ; }
while ( '' <= ch && ch <= '' ) { x = ( x << ) + ( x << ) + ch - '' ; ch = getchar ( ) ; }
return x * f ;
} void Pre_Init ( int n ) {
for ( int i= ; i<=_max ; ++i )
Sum[ i ] = Sum[ i - ] + buc[ i ] ;
} inline QAQ gmax ( QAQ x , QAQ y ) { return x > y ? x : y ; }
inline QAQ gmin ( QAQ x , QAQ y ) { return x > y ? y : x ; } int main ( ) {
QAQ Ans = -INF , _max = -INF ;
int N = INPUT ( ) ;
for ( int i= ; i<=N ; ++i ) {
int tmp = INPUT ( ) ;
++ buc [ tmp ] ;
_max = gmax ( _max , tmp ) ;
} Pre_Init ( _max ) ; for ( int i= ; i<=_max ; ++i ) {
if ( !buc[ i ] ) continue ;
QAQ rest = ;
for ( int j=i ; j<=_max ; j+=i ) {
rest += ( Sum[ gmin ( i + j - , _max ) ] - Sum [ j - ] ) * j ;
}
Ans = gmax ( Ans , rest ) ;
}
cout << Ans << endl ;
return ;
}
2016-10-18 10:45:39
(完)
Codeforces #Round 376 F 题解的更多相关文章
- Codeforces #Round 376 部分题解
A: 题目传送门:http://codeforces.com/problemset/problem/731/A 直接根据题意模拟即可 #include "bits/stdc++.h" ...
- Codeforces Round #543 Div1题解(并不全)
Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...
- Codeforces Round #545 Div1 题解
Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...
- Codeforces Round #539 Div1 题解
Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有 ...
- Educational Codeforces Round 64 部分题解
Educational Codeforces Round 64 部分题解 不更了不更了 CF1156D 0-1-Tree 有一棵树,边权都是0或1.定义点对\(x,y(x\neq y)\)合法当且仅当 ...
- Educational Codeforces Round 64部分题解
Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
- Codeforces Round div2 #541 题解
codeforces Round #541 abstract: I构造题可能代码简单证明很难 II拓扑排序 III并查集 启发式排序,带链表 IV dp 处理字符串递推问题 V 数据结构巧用:于二叉树 ...
- [Codeforces Round #461 (Div2)] 题解
[比赛链接] http://codeforces.com/contest/922 [题解] Problem A. Cloning Toys [算法] 当y = 0 , 不可以 当 ...
随机推荐
- 解析PHP处理换行符的问题 \r\n
一首先说说 \r 与\n的区别回车”(Carriage Return)和“换行”(Line Feed)这两个概念的来历和区别.在计算机还没有出现之前,有一种叫做电传打字机(Teletype Model ...
- WebApiのエラーメッセージをどうカスタマイズです?
本来是发布在客户的Wiki上,所以就用日语写. ------------------------------------------------------------------------ Web ...
- lvs+keepalived 负载均衡
LVS是一个开源的软件,可以实现LINUX平台下的简单负载均衡.LVS是Linux Virtual Server的缩写,意思是Linux虚拟服务器.目前有三种IP负 载均衡技术(VS/NAT.VS/T ...
- Golang Beego 分析(一)
关于注解路由,实质上其实是comment route. 作者使用ast自动生成注册代码,实质上感觉是画蛇添足了. 有一定的使用价值,但是在代码管理上反而混乱了.所以本人建议不要使用此项特性.
- html5 离线存储 worker
html5 离线存储 <!DOCTYPE html> <html manifest="cache.manifest"> <!--manifest存储- ...
- 如何实现Outlook 2010 下载邮件后自动删除服务器上的邮件
outlook2010---文件---信息---账户设置---选中要设置的帐号---双击点选要设置的邮箱---其他设置---高级---在服务器上保留邮件的副本---14天后删除服务器上的邮件副本,修改 ...
- 学习iOS的网站
ios开发者 http://www.codeios.com/ cocoachina http://www.cocoachina.com code4app http://code4app.com ...
- 通信原理实践(四)——模拟通信系统性能分析
一.模拟通信系统性能分析 1.系统框图 2.信噪比定义 (1)输入信噪比: (2)输出信噪比: (3)调制制度增益: 3.模拟通信系统分析等价模型 即自己产生一个高斯白噪声,加入到调制信号,然后在送入 ...
- HTML的格式、内容容器、表格标签
HTML(Hyper Text Markup Language,超文本标记语言)超指的是超链接. <html> --开始标签 <head> 网页上的控制信息 <ti ...
- java基本数据类型及相互间的转换
1.首先复习一下java的基本数据类型,见下图 2.比较他们的字节数 备注:1字节(Byte)=8位(Bit) 3.转换中的知识点 *java中整数类型默认的int类型:小数类型默认的double: ...