B. Vika and Squares
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains ai liters of paint of color i.

Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1 × 1. Squares are numbered 1, 2, 3 and so on. Vika decided that she will start painting squares one by one from left to right, starting from the square number 1 and some arbitrary color. If the square was painted in color x, then the next square will be painted in color x + 1. In case of x = n, next square is painted in color 1. If there is no more paint of the color Vika wants to use now, then she stops.

Square is always painted in only one color, and it takes exactly 1 liter of paint. Your task is to calculate the maximum number of squares that might be painted, if Vika chooses right color to paint the first square.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of jars with colors Vika has.

The second line of the input contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is equal to the number of liters of paint in the i-th jar, i.e. the number of liters of color i that Vika has.

Output

The only line of the output should contain a single integer — the maximum number of squares that Vika can paint if she follows the rules described above.

Examples
Input
5
2 4 2 3 3
Output
12
Input
3
5 5 5
Output
15
Input
6
10 10 10 1 10 10
Output
11
Note

In the first sample the best strategy is to start painting using color 4. Then the squares will be painted in the following colors (from left to right): 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5.

In the second sample Vika can start to paint using any color.

In the third sample Vika should start painting using color number 5.

题意:

懒得讲。

思路:

记得用long long!!

#include<iostream>
using namespace std;
#define ll long long
int a[];
int main()
{
ll m,i,len,ans,minn=,minx; cin>>m;
for(i=;i<m;i++){
cin>>a[i];
a[i+m] = a[i];
if(a[i]<minn){
minn = a[i];
minx = i;
}
}
//cout<<minn<<endl;
for(i=;i<*m;i++)
a[i] -= minn;
len = ;
ans = ;
for(i=minx+;i<=minx+m;i++){
if(a[i]==){
if(ans>len)
len = ans;
ans=;
}
else
ans++;
}
//cout<<len<<endl;
ll sum = len+minn*m;
cout<<sum<<endl;
}

Codeforces Round #337 (Div. 2) B. Vika and Squares的更多相关文章

  1. Codeforces Round #337 (Div. 2) B. Vika and Squares 贪心

    B. Vika and Squares 题目连接: http://www.codeforces.com/contest/610/problem/B Description Vika has n jar ...

  2. Codeforces Round #337 (Div. 2) B. Vika and Squares 水题

    B. Vika and Squares   Vika has n jars with paints of distinct colors. All the jars are numbered from ...

  3. Codeforces Round #337 (Div. 2) 610B Vika and Squares(脑洞)

    B. Vika and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树扫描线

    D. Vika and Segments 题目连接: http://www.codeforces.com/contest/610/problem/D Description Vika has an i ...

  5. Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树 矩阵面积并

    D. Vika and Segments     Vika has an infinite sheet of squared paper. Initially all squares are whit ...

  6. Codeforces Round #337 (Div. 2) D. Vika and Segments (线段树+扫描线+离散化)

    题目链接:http://codeforces.com/contest/610/problem/D 就是给你宽度为1的n个线段,然你求总共有多少单位的长度. 相当于用线段树求面积并,只不过宽为1,注意y ...

  7. Codeforces Round #337 (Div. 2)

    水 A - Pasha and Stick #include <bits/stdc++.h> using namespace std; typedef long long ll; cons ...

  8. Codeforces Round #337 (Div. 2)B

    B. Vika and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #337 (Div. 2) C. Harmony Analysis 构造

    C. Harmony Analysis 题目连接: http://www.codeforces.com/contest/610/problem/C Description The semester i ...

随机推荐

  1. OSGeo.OGR.Geometry

    #region 程序集 ogr_csharp.dll, v2.0.50727 // D:\KM行业需求\C++\gdal17_cSharp\ogr_csharp.dll #endregion usin ...

  2. CF939D Love Rescue 并查集

    传送门 题意:给出两个由小写字母构成的长度相等的字符串$S$与$T$,给出变换$c1\,c2$表示将两个字符串中所有$c1$字符变为$c2$,求将$S$和$T$通过这种变换变为相等字符串的最少变换次数 ...

  3. Sharding模式

    将数据存储为一组水平的数据分区.这种模式可以在存储和访问大量的数据的时候提高可扩展性. 场景和问题 由单个服务器托管的数据存储可能受到下列限制: 存储空间限制.基于大规模云应用所使用的数据仓库,可能会 ...

  4. 爬虫学习--http请求详解

    上篇博客里面写了,爬虫就是发http请求(浏览器里面打开发送的都是http请求),然后获取到response,咱们再从response里面找到想要的数据,存储到本地. 咱们本章就来说一下什么是http ...

  5. ansible环境部署及常用模块总结 - 运维笔记

    一.  Ansible 介绍Ansible是一个配置管理系统configuration management system, python 语言是运维人员必须会的语言, ansible 是一个基于py ...

  6. webvirtmgr-重命名kvm虚拟机的名称

    之前部署了Webvirtmgr平台管理kvm虚拟机,由于虚拟机在创建时名称是顺便起的,后续在虚拟机上部署了部分业务.为了便于管理,最好将虚拟机的名称重置下. 现在说下如何修改kvm中虚拟机的名称: 比 ...

  7. 《Linux内核分析》第六周学习总结

    <Linux内核分析>第六周学习总结                         ——进程的描述和进程的创建 姓名:王玮怡  学号:20135116 一.理论部分 (一)进程的描述 1 ...

  8. js实现树形内容展示

    1.首先这里有一个demo,里边有封装好的js文件.地址:http://files.cnblogs.com/files/feifeishi/dtree.zip 2.直接上代码 <div styl ...

  9. Quartz学习(转)

    Quartz, 是一个企业级调度工作的框架,帮助Java应用程序到调度工作/任务在指定的日期和时间运行. 一.在Java工程中使用Quartz 1.导入jar包 com.springsource.or ...

  10. [问题解决]基于注解配置dubbo遇到ConnectionLoss for /dubbo/xxx问题解决

    今天升级spring版本的时候,同时升级dubbo的版本,采用的是dubbo的基于注解的配置方法,采用curator作为dubbo的客户端, curator版本为4.1.0,启动之后,发现一直报错 C ...