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. Delphi内嵌汇编语言BASM精要(转帖)

    1 BASM概念简要  汇编语句由指令和零至三个表达式构成.表达式由常数(立即数).寄存器和标识符构成.例如: movsb        // 单指令语句 jmp @Here    // 一个表达式: ...

  2. android listview万能适配器

    参考    Android 快速开发系列 打造万能的ListView GridView 适配器 Hongyang public class CommonViewHolder { private Con ...

  3. Git几块区域关系

  4. JavaScript中统计Textarea字数并提示还能输入的字符

    <span style="font-size:18px;"><script language="javascript"> functio ...

  5. ORACLE添加表约束的语法示例

    转自:http://jingyan.baidu.com/article/f54ae2fccda68d1e93b84942.html 示例: --班级表 CREATE TABLE TCLASS( cl_ ...

  6. PHP String 函数

    [http://www.w3school.com.cn/php/php_ref_string.asp ] PHP String 简介 String 字符串函数允许您对字符串进行操作. 安装 Strin ...

  7. StringBuffer类的方法

    public class Page116 { /** * StringBuffer类的练习 * @param args * @throws IOException */ public static v ...

  8. 只使用处理I/O的PrintDigit函数,编写一个过程以输出任意实数

    #include <stdio.h> #include <stdlib.h> #include <math.h> int printDigit(int a) { p ...

  9. Winform中如何实现父窗体传递数据到子窗体并刷新子窗体

    原理:利用委托和事件,本文将以图文并茂的例子讲述,告诉我们So Easy --------------------------------------------------------------- ...

  10. 分页sql存储过程算法

    /****** Object: StoredProcedure [dbo].[PRO_Pub_FenYe] Script Date: 08/04/2014 11:14:22 ******/ SET A ...