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.

分析:从小到大枚举每个数的倍数即可;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fLL
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<ll,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
const int maxn=4e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,a[maxn],b[maxn];
ll ans,now;
set<int>p;
int main()
{
int i,j;
scanf("%d",&n);
rep(i,,n)scanf("%d",&a[i]),b[a[i]]++,p.insert(a[i]);
sort(a+,a+n+);
rep(i,,*a[n])b[i]+=b[i-];
for(int x:p)
{
now=0LL;
for(j=;(ll)x*(j-)<=a[n];j++)
{
now+=(ll)(b[x*j-]-b[x*(j-)-])*((ll)x*(j-));
}
ans=max(ans,now);
}
printf("%lld\n",ans);
//system("Pause");
return ;
}

Video Cards的更多相关文章

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

    F. Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. 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 ...

  3. 【19.05%】【codeforces 731F】 Video Cards

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

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

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

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

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

  6. Codeforces 731F Video Cards

    题意:给定n个数字,你可以从中选出一个数A(不能对该数进行修改操作),并对其它数减小至该数的倍数,统计总和.问总和最大是多少? 题解:排序后枚举每个数作为选出的数A,再枚举其他数, sum += a[ ...

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

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

  8. Codeforces731F Video Cards

    考虑每个数在最大值内的倍数都求出来大概只有max(ai)ln(max(ai))个. 先排个序,然后对于每个数ai,考虑哪些数字可以变成ai*k. 显然就是区间[ai*k,ai*(k+1))内的数,这个 ...

  9. CodeForces 731F Video Cards (数论+暴力)

    题意:给定 n 个数,可以对所有的数进行缩小,问你找出和最大的数,使得这些数都能整除这些数中最小的那个数. 析:用前缀和来做,先统计前 i 个数中有有多少数,然后再进行暴力去找最大值,每次都遍历这一段 ...

随机推荐

  1. jQuery第五章

    jQuery对表单.表格的操作以及更多应用 一.表单应用 1.单行文本框应用 (1)获取和失去焦点改变样式 HTML代码如下: <form action="#" method ...

  2. swift 2中关键字和解释整理

    1.swift 最新关键字和符号参考:https://developer.apple.com/library/mac/documentation/Swift/Conceptual/Swift_Prog ...

  3. 4、Spring+MyBatis增删改查

    0.oracle数据库脚本 create table userinfo (id ), name ), password telephone ), isadmin )); --4.2 用户表序列 cre ...

  4. 京东商品hover效果

    代码: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&q ...

  5. 【转】Spring事务超时时间可能存在的错误认识

    1.先看代码 1.1.spring-config.xml <bean id="dataSource" class="org.springframework.jdbc ...

  6. 2014web面试题

    面试题目会根据你的等级和职位变化,入门级到专家级:范围↑.深度↑.方向↑; 类型: 技术视野.项目细节.理论知识型题,算法题,开放性题,案例题. 进行追问,可以确保问到你开始不懂或者面试官开始不懂为止 ...

  7. (转载)app ico图标字体制作

    图标字体化浅谈   在做手机端Web App项目中,经常会遇到小图标在手机上显示比较模糊的问题,经过实践发现了一种比较好的解决方案,图标字体化.在微社区项目中,有很多小的Icon(图标),如分享.回复 ...

  8. 调用CImg库显示WAV格式音频波形

    最近在做傅里叶变换和小波变换时经常要通过显示波形来检验算法,但通过visual studio之类显示波形又显得麻烦,而且不能跨平台. CImg是一个跨平台的C++的图像处理库,提供的图像处理等功能十分 ...

  9. Neutron 不健全的HA ROUTER

    首先介绍下HA,所谓的HA就是高可用性,但HA有双主.主备两种工作模式,其中主备模式又包含抢占与 非抢占两种方式,而Neutron Router采用的无疑是HA中最简单的工作方式非抢占主备模式. HA ...

  10. html_web存储

    HTML5存储 HTML5 web存储,一个比cookie更好的本地存储方式. 什么是HTML5 Web存储? 使用HTML5可以在本地存储用户的浏览数据. 早些时候,本地存储使用的是cookie.但 ...