CodeForces 610B Vika and Squares

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int maxn=200000+10;
long long a[maxn],n;
long long  Min;
long long ans;
long long b[maxn];

int main()
{
    while(~scanf("%lld",&n)){
        Min=99999999999;
        for(long long  i=1;i<=n;i++) scanf("%lld",&a[i]);
        for(long long  i=1;i<=n;i++) if(a[i]<Min) Min=a[i];
        int tot=0;
        for(long long i=1;i<=n;i++) if(a[i]==Min) b[tot++]=i;
        ans=-99999999999;
        for(int i=0;i<tot;i++)
        {
            if(i<tot-1)
            {
                long long ans2=(Min)*(n-b[i+1]+1+b[i])+(Min+1)*(b[i+1]-b[i]-1);
                ans=max(ans,ans2);
            }
            else if(i==tot-1)
            {
                long long ans2=(Min+1)*(n-b[i]+b[0]-1)+Min*(b[i]-b[0]+1);
                ans=max(ans,ans2);
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

 

posted @ 2015-12-31 12:57  Fighting_Heart  阅读(240)  评论(0编辑  收藏  举报