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. What is SaaS?

    SaaS, or Software as a Service, describes any cloud service where consumers are able to access softw ...

  2. How to handle the DbEntityValidationException in C#

    When I want to use db.SaveChanges(), if some of the columns got validation error and throw DbEntityV ...

  3. 关于JavaScript的类的继承

    其实最一开始学JS的时候就看过继承的实现.当时只是去试着理解从书上看来的代码段而已.今天又重新思考了一下,感觉这是一个思维探索演进的结果. 继承,即复用. 如果抛开继承的固有思想,让b复用a的成员,最 ...

  4. ios开发之xcode6中如何添加pch全局引用文件

    xcode6中去掉了默认添加pch文件,这就需要我们自己手动添加pch文件了,添加pch文件是为了一些琐碎的头文件引用,加快编译速度! 下面就说下该如何手动添加pch文件: 1.添加一个文件,在oth ...

  5. 利用js获取时间并输出值

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  6. wpf样式绑定 行为绑定 事件关联 路由事件实例

    代码说明:我要实现一个这样的功能  有三个window窗口  每个窗体有一个label标签  当我修改三个label标签中任意一个字体颜色的时候  其他的label标签字体颜色也变化 首先三个窗体不用 ...

  7. AJAX编程模板

    AJAX一直以来没怎么接触,主要是做JSON数据在服务器和客户端之间传递的时候,被玩坏了,对它莫名的不可爱,最近心理阴影小了,于是又来看看它....... AJAX即“Asynchronous Jav ...

  8. Keil的使用-1创建项目和工程

    下载keil,注意不要使用MDK版本(主要是arm开发使用),大小约54M 安装过程不再详述 安装Keil成功并运行后,新建项目,   创建新项目,然后弹出下图,选择对应的单片机芯片(双击)     ...

  9. apt-cache madison package-name

    apt-cache madison package-name 搜索软件有那些可用版本,

  10. 使用appium做自动化时如何切换activity

    在使用appium过程中遇到了执行一个用例时有多个不同的acitivity的情况,以下为app内部切换acitivity的方法: 如果仅需要切换一次activity,可以通过设置desired_cap ...