码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 610B

时间:2016-07-22 21:16:17      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

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


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


 1 #include <stdio.h>
 2 #include <iostream>
 3 using namespace std;
 4 #define Maxn 210000
 5 #define INF 1500000000
 6 
 7 struct Node
 8 {
 9     long long int num;
10 }N[Maxn];
11 
12 int main()
13 {
14     long long int T;
15     scanf("%lld",&T);
16     long long int min = INF;
17     long long int flag_big;
18     long long int flag_small;
19     long long int flag;
20     long long int bigger;
21     bool Q = false;
22     for(int i = 1; i <= T; i++)
23     {
24         scanf("%lld",&N[i].num);
25         if (min > N[i].num)
26         {
27             min = N[i].num;
28             flag = i;
29         }
30     }
31     if (T == 1)
32     {
33         printf("%lld\n",N[1].num);//我在这里错了十发- -
34         return 0;
35     }
36     flag_small = flag;
37     for(int i = 1; i <= T; i++)
38     {
39         if (min == N[i].num && flag < i)
40         {
41             flag = i;
42             Q = true;
43         }
44     }
45     flag_big = flag;
46     long long int biggest;
47     bigger = T - flag_big + flag_small -1;
48     long long int count = 0;
49     long long int cnt = 0;
50     if (Q)
51     {
52         for(int i = flag_small; i <= T; i++)
53         {
54             if (N[i].num == min)
55             {
56                 count = i - flag_small-1;
57                 flag_small = i;
58             }
59             if (count > cnt)
60             {
61                 cnt = count;
62             }
63         }
64         biggest = max(cnt,bigger);
65         //long long Fuck;
66         //Fuck = T*min;
67         printf("%lld\n",T*min + biggest);
68     }
69     else
70     {
71         printf("%lld\n",T*min + T-1);
72     }
73 }

 

codeforces 610B

标签:

原文地址:http://www.cnblogs.com/yakoazz/p/5696956.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!