国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

【Codeforces 731 F Video Cards】

2019-11-11 06:47:07
字體:
來源:轉載
供稿:網友

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.

以a[i]為leading,a[i] * 2 ~ a[i] * 3 - 1 內的數的貢獻均為 a[i] * 2

AC代碼 :

#include<cstdio>#include<algorithm>using namespace std;const int K = 4e5 + 10;typedef long long LL;LL sum[K],num[K];int main(){ LL N,a,mx = 0,ans = 0; scanf("%lld",&N); for(int i = 1 ; i <= N; i++) scanf("%lld",&a),num[a]++,mx = max(mx,a); for(int i = 1 ; i < K; i++) sum[i] = sum[i - 1] + num[i]; for(int i = 1 ; i <= mx; i++) if(num[i]){ LL cut = 0; for(int j = i ; j <= mx; j += i) cut += (sum[j + i - 1] - sum[j - 1]) * j; ans = max(ans,cut); }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安西县| 古交市| 普定县| 潼关县| 田阳县| 玉田县| 巫溪县| 汾西县| 清流县| 噶尔县| 南华县| 兴文县| 禹州市| 永安市| 昌图县| 微博| 井研县| 新野县| 庆阳市| 太仆寺旗| 会理县| 大埔区| 安吉县| 定南县| 海口市| 沙坪坝区| 越西县| 南雄市| 沅陵县| 思南县| 廉江市| 隆林| 灵丘县| 彝良县| 樟树市| 余庆县| 崇左市| 金川县| 安阳市| 武威市| 葵青区|