• Video Cards


    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+10;
    using namespace std;
    ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
    ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
    inline ll read()
    {
        ll x=0;int f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';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,1,n)scanf("%d",&a[i]),b[a[i]]++,p.insert(a[i]);
        sort(a+1,a+n+1);
        rep(i,1,2*a[n])b[i]+=b[i-1];
        for(int x:p)
        {
            now=0LL;
            for(j=2;(ll)x*(j-1)<=a[n];j++)
            {
                now+=(ll)(b[x*j-1]-b[x*(j-1)-1])*((ll)x*(j-1));
            }
            ans=max(ans,now);
        }
        printf("%lld
    ",ans);
        //system("Pause");
        return 0;
    }
  • 相关阅读:
    J2SE-反射
    c3p0 连接数据库失败的问题
    c# 调用存储过程
    存储过程使用truncate时
    Parcelable intent传递对象时,需要将该对象实现Parcelable 或者Serializable
    android intent 在打开设置activity的时候在监听事件的内部 适用setclass()方法时 不是直接适用this 关键字
    c# 读取appconfig文件
    Oracle 连接数据库的几种方式
    通过反射获得方法,和绑定事件
    js 验证
  • 原文地址:https://www.cnblogs.com/dyzll/p/5967789.html
Copyright © 2020-2023  润新知