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. LeetCode263:Ugly Number

    public bool IsUgly(int num) { if(num<1) return false; while(num>1) { if(num%2==0) { num=num/2; ...

  2. SerialPort.h SerialPort.cpp

    SerialPort.h 1 #ifndef __SERIALPORT_H__ 2 #define __SERIALPORT_H__ 3 4 #define WM_COMM_BREAK_DETECTE ...

  3. IIS导入.pfx证书时报错:"A specified logon session does not exist. It may already have been terminated."

    在IIS中可以直接导入.pfx文件来给站点绑定https协议: 如果在导入.pfx文件时,不选择"Allow this certificate to be exported"的话 ...

  4. Luogu P2522 [HAOI2011]Problem b

    如果你做过[Luogu P3455 POI2007]ZAP-Queries就很好办了,我们发现那一题求的是\(\sum_{i=1}^a\sum_{j=1}^b[\gcd(i,j)=d]\),就是这道题 ...

  5. [清华集训2017]榕树之心[树dp]

    题意 题目链接 分析 首先解决 \(subtask3\) ,我们的策略就是进入子树,然后用其它子树来抵消,注意在子树内还可以抵消. 可以转化为此模型:有一个数列 \(a\) ,每次我们可以选定两个值 ...

  6. C# 获取文件MD5值的方法

    可用于对比文件是否相同 /// <summary> /// 获取文件MD5值 /// </summary> /// <param name="fileName& ...

  7. ActiveMQ 填坑记

    前言 MQ是现在大型系统架构中必不可少的一个重要中间件,之前有偏文章<MQ(消息队列)常见的应用场景解析>介绍过MQ的应用场景,现在流行的几个MQ是rabbitmq,rocketma,ka ...

  8. Bash Shebang 小结

    在 shell(Bash 是一种 shell) 中执行外部程序和脚本时,Linux 内核会启动一个新的进程,以便在新的进程中执行指定的程序或脚本.内核知道该如何为编译型的程序做这件事,但是对于脚本程序 ...

  9. host大法之GitHub上不去

    dns解析慢,github上不去,慢 修改host. windows下路径为:C:\Windows\System32\drivers\etc\hosts Linux下路径:/etc/hosts 加入: ...

  10. ecna2017-Sheba’s Amoebas

    很简单的深搜的一道题,由于这道题要找环的个数,并且认为相连当一个点的8个方向种中有一个方向和这个点相连. 这个题做法无非就是暴力每个点,然后满足条件的深搜即可. 感觉我自己的代码写的很无趣,大佬的代码 ...