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. NOIP2002-2017普及组题解

    虽然普及组一般都是暴力省一,但是有一些题目还是挺难的qwq个人觉得能进TG的题目会在前面打上'*' NOIP2002(clear) #include<bits/stdc++.h> usin ...

  2. BZOJ4856 JSOI2016 病毒感染 区间DP

    传送门 原Word文档 题意:太长不给 这种题目一看就是区间DP 设$f_i$表示治愈了前$i$个村子的时候最少死了多少村民,又设前缀和为$sum_i$,通过枚举折返时最后经过的村子$j$,并且提前计 ...

  3. React-使用styled-components

    1.安装 npm install --save styled-components 2.简单使用 style.js: import styled from 'styled-components'; i ...

  4. Scala学习(七)---包和引入

    包和引入 摘要: 在本篇中,你将会了解到Scala中的包和引入语句是如何工作的.相比Java不论是包还是引入都更加符合常规,也更灵活一些.本篇的要点包括: 1. 包也可以像内部类那样嵌套 2. 包路径 ...

  5. Mvc_ActionResult返回值

    //ViewResult 表示HTML的页面内容 //EmptyResult 表示空白的页面内容 //RedirectResult 表示定位到另外一个URL //JsonResult 表示可以运用到A ...

  6. Tomcat通过Redis实现session共享的完整部署记录

    对于生产环境有了一定规模的tomcat集群业务来说,要实现session会话共享,比较稳妥的方式就是使用数据库持久化session.为什么要持久化session(共享session)呢?因为在客户端每 ...

  7. Docker环境编译时的错误记录

    1)报错一docker-compose -f compose/app.yaml -f compose/backend.yaml -f compose/proxy.yaml build peatio b ...

  8. Centos 6.9下部署Oracle 11G数据库环境的操作记录

    操作系统:Centos6.9(64Bit)Oracle:11g .11.2.0.4.0版本Ip地址:172.16.220.139 废话不多说了,下面记录安装过程:1)安装桌面环境 [root@vm01 ...

  9. 领跑衫获奖感言 & 课程总结

    很荣幸在最后一次课获得了黄色领跑衫.在此,我要感谢教师杨贵福,感谢<构建之法>的作者邹欣老师和出版人周筠老师,感谢“耐撕”团队的队员们. 作为旁听生,最后一堂课,有些不舍.不多说,先上图, ...

  10. SQL大杂烩

    DML 语句(数据操作语言)Insert.Update. Delete.Merge DDL 语句(数据定义语言)Create.Alter. Drop.Truncate DCL 语句(数据控制语言)Gr ...