F. Video Cards
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

The only line of the output should contain one integer value — the maximum possible total power of video cards working together.

Examples
input
4
3 2 15 9
output
27
input
4
8 2 2 7
output
18
Note

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.

题意:给你n个数,max((i=1-n)sigma(j=1-n)(a[j]-a[j]%a[i]);

思路:枚举每个数,再枚举它的倍数,利用前缀和得到(base *k- base*(k+1))之间的个数;复杂度o(nlogn);

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=1e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
int sum[N],a[N];
int main()
{
int n,x;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&x),a[x]++;
for(int i=;i<=;i++)sum[i]=sum[i-]+a[i];
ll ans=;
for(int i=;i<=;i++)
{
if(a[i])
{
ll s=;
for(int j=;j<=;j+=i)
{
int nex=min(,j+i-);
if(j!=)
s+=(ll)(sum[nex]-sum[j-])*j;
}
ans=max(ans,s);
}
}
printf("%lld\n",ans);
return ;
}

Codeforces Round #376 (Div. 2) F. Video Cards 数学,前缀和的更多相关文章

  1. Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)

    题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...

  2. Codeforces Round #376 (Div. 2) F. Video Cards 数学 & 暴力

    http://codeforces.com/contest/731/problem/F 注意到一个事实,如果你要找一段区间中(从小到大的),有多少个数是能整除左端点L的,就是[L, R]这样.那么,很 ...

  3. Codeforces Round #376 (Div. 2) F. Video Cards —— 前缀和 & 后缀和

    题目链接:http://codeforces.com/contest/731/problem/F F. Video Cards time limit per test 1 second memory ...

  4. Codeforces Round #585 (Div. 2) A. Yellow Cards(数学)

    链接: https://codeforces.com/contest/1215/problem/A 题意: The final match of the Berland Football Cup ha ...

  5. Codeforces Round #485 (Div. 2) F. AND Graph

    Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...

  6. Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  7. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  8. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  9. Codeforces 731 F. Video Cards(前缀和)

    Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...

随机推荐

  1. keepalived+mysql主主

    实验架构图: 一.mysql 5.5双机热备份 master-master 1.系统环境 操作系统:centos6.6 masterA IP:192.168.166.161 masterB ip:19 ...

  2. CSS修改方法

    1.在IE中,大部分情况下默认margin = 0px padding = 0px,但在Chrome中需要写明 在css.css文件开头加上(要加在最上面) html,body,ul,ol,li,ta ...

  3. weblogic的jar包冲突

    异常: Error creating bean with name 'sessionFactoryWrite' defined in class path resource [applicationC ...

  4. mount/umount系统调用

    转载自:http://blog.sina.com.cn/s/blog_6385c7310100iqmn.html 功能描述: mount挂上文件系统,umount执行相反的操作.    用法:   # ...

  5. 超文本标记语言(HTML)

    超文本标记语言(HyperText MarkUp Language,HTML) HTML是用来制作网页的标记语言,HTML不需要编译,直接由浏览器解析: HTML文件是一个文本文件,包含了一些HTML ...

  6. CentOS安装、卸载jdk

    安装:http://www.mamicode.com/info-detail-613410.html 卸载:http://sunqiusong.email.blog.163.com/blog/stat ...

  7. LightOJ1002 分类: 比赛 最短路 2015-08-08 15:57 15人阅读 评论(0) 收藏

    I am going to my home. There are many cities and many bi-directional roads between them. The cities ...

  8. mysql replication之binlog-do-db、binlog-ignore-db

    再次整理管理mysql复制的资料,一直搞不明白为什么mysql的启动参数里面有两个binlog-do-db.binlog-ignore-db 这次仔细的阅读了mysql的帮助手册,整理一下对于一条语句 ...

  9. 网站性能优化之CSS无图片技术:三角形

    1.使用CSS无图片技术,可以总结得到以下三个优点: 减少请求资源的大小: 减少http的请求个数: 提高可维护性. 一.CSS无图片技术,微博中有哪些实际应用呢? 通过上面的展示,我们可以看到,无图 ...

  10. java的myeclipse生成webservice的service和client

    前言:朋友们开始以下教程前,请先看第五大点的注意事项,以避免不必要的重复操作. 一.准备工作(以下为本实例使用工具) 1.MyEclipse10.7.1 2.JDK 1.6.0_22 二.创建服务端 ...