Description

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.

Sample Input

Input
52 4 2 3 3
Output
12
Input
35 5 5
Output
15
Input
610 10 10 1 10 10
Output
11

要涂油漆,有T(需要输入)种油漆,每种编号1,2,3,4....,没涂完一次,下一种油漆序号要比第一种大,如果到最大,那下一种就是1,输入各种油漆的数量,问你最多能涂多少油漆

 #include <stdio.h>
 #include <iostream>
 using namespace std;
 #define Maxn 210000
 #define INF 1500000000

 struct Node
 {
     long long int num;
 }N[Maxn];

 int main()
 {
     long long int T;
     scanf("%lld",&T);
     long long int min = INF;
     long long int flag_big;
     long long int flag_small;
     long long int flag;
     long long int bigger;
     bool Q = false;
     ; i <= T; i++)
     {
         scanf("%lld",&N[i].num);
         if (min > N[i].num)
         {
             min = N[i].num;
             flag = i;
         }
     }
     )
     {
         printf(].num);//我在这里错了十发- -
         ;
     }
     flag_small = flag;
     ; i <= T; i++)
     {
         if (min == N[i].num && flag < i)
         {
             flag = i;
             Q = true;
         }
     }
     flag_big = flag;
     long long int biggest;
     bigger = T - flag_big + flag_small -;
     ;
     ;
     if (Q)
     {
         for(int i = flag_small; i <= T; i++)
         {
             if (N[i].num == min)
             {
                 count = i - flag_small-;
                 flag_small = i;
             }
             if (count > cnt)
             {
                 cnt = count;
             }
         }
         biggest = max(cnt,bigger);
         //long long Fuck;
         //Fuck = T*min;
         printf("%lld\n",T*min + biggest);
     }
     else
     {
         printf();
     }
 }

codeforces 610B的更多相关文章

  1. CodeForces 610B Vika and Squares

    #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using ...

  2. 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 ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. Linux系统swap已分区但无法挂载与cryptswap1问题

    linux下察看swap分区大小的命令 top 或者fdisk -l 或者free -m SWAP分区一般大小为物理内存的2倍,但最大不超过2G; 增加SWAP空间的方法有两个:增加另外一个SWAP分 ...

  2. 最简单的基于FFmpeg的移动端例子:IOS 推流器

    转至:http://blog.csdn.net/leixiaohua1020/article/details/47072519   ================================== ...

  3. Vijos1523 NOI2002 贪吃的九头龙 树形dp

    思路不算很难,但细节处理很麻烦 前面建图.多叉转二叉,以及确定dp处理序列的过程都是套路,dp的状态转移过程以注释的形式阐述 #include <cstdio> #include < ...

  4. 【POJ3237】【树链剖分】Tree

    Description You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edg ...

  5. Jquery实现图片左右滚动(自动)

    <!DOCTYPE HTML><html><head><title>基于jQuery的控制左右滚动效果_自动滚动版本</title>< ...

  6. java设计模式——单例(Singleton)模式

    在某些场景,你需要找到一个承担职责的对象,并且这个对象是他所属类的唯一实例.此时可以使用单例模式. 单例模式的意图是为了确保一个类有且仅有一个实例,并为他提供一个全局的访问点.创建一个担当独一无二角色 ...

  7. LAMP的编译日志,

    在CentOS5.2上,编译LAMP的,两年前测试通过的,现在留印 ### 在记事本中 ,不要打开 自动换行,否则一些命令 无法正常运行###把源文件考到/src/目录下,然后进入/src////// ...

  8. 基于jQuery 的图片瀑布流实现

    解题思路: 第1步  分析问题:我这边的处理方式是以列为单位.每次滚动条滚到底部,把需要加的新的内容放在高度最小的列.如下图所示 加载后的显示 如果在继续往下滚动.新图片就会在1下边显示,如此类推. ...

  9. 极简主义,对逻辑操作符||和&&深度运用的理解

    丧心病狂的代码压缩好像违背了愉快阅读的本真,所以刨根问底想要了解个究竟,最后发现这不只是前端大牛装逼卖萌的绝技,也是代码洁癖爱好者的利器,毕竟这样看上去确实蛮优雅的; 一开始,我们接触到的代码是这样的 ...

  10. QQ弹窗代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...