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 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
5
2 4 2 3 3
Sample Output
12
Hint
题意
你有n种颜色,然后每种颜色有ai个,你需要依次涂色。
比如第一个你涂x,那么下一个就得涂x+1,然后x+2.....
问你最多能涂多少个格子
题解:
贪心一下,我们肯定从最小的后面一格开始走。
这样可以得到答案,是 n * min + tmp
tmp是多少呢?tmp是最小值的两个之间的差值中最大的那个
证明略 hhh
代码
#include<bits/stdc++.h>
using namespace std;
int Min = 1e9+5,ans=0;
int a[200005];
vector<int>P;
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
{
if(Min>=a[i])
{
Min = a[i];
ans = i;
}
}
int first = 0;
for(int i=1;i<=n;i++)
{
if(a[i]==Min)
P.push_back(i);
}
P.push_back(P[0]+n);
long long tmp = 0;
for(int i=1;i<P.size();i++)
tmp = max(tmp,1LL*P[i]-1LL*P[i-1]-1LL);
printf("%lld\n",1LL*n*Min+1LL*tmp);
}
Codeforces Round #337 (Div. 2) B. Vika and Squares 贪心的更多相关文章
- 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 ...
- Codeforces Round #337 (Div. 2) B. Vika and Squares
B. Vika and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments (线段树+扫描线+离散化)
题目链接:http://codeforces.com/contest/610/problem/D 就是给你宽度为1的n个线段,然你求总共有多少单位的长度. 相当于用线段树求面积并,只不过宽为1,注意y ...
- Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #337 (Div. 2)
水 A - Pasha and Stick #include <bits/stdc++.h> using namespace std; typedef long long ll; cons ...
- Codeforces Round #337 (Div. 2)B
B. Vika and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- WeifenLuo.WinFormsUI.Docking"的使用 z
在伍华聪的博客中,看到布局控件"WeifenLuo.WinFormsUI.Docking",发现的确是一个非常棒的开源控件,用过的人都深有体会,该控件之强大.美观.不亚于商业控件. ...
- jquery图片裁切+PHP文件上传
下载地址:download.csdn.net/source/2745353
- 使用clipboard.js复制页面内容到剪切板
最近在做一个的智能客服Web端浏览器应用,其中有一项需求是客户在获取系统返回的 答案后点击“复制答案”按钮将答案复制到系统剪切板.本以为这是一个小case,但是发现如果 要对各种主流浏览器都有良好的兼 ...
- VS如何设置OpenCV静态编译
可以使用opencv提供的静态链接库也可以自己编译静态链接库. 1 使用opencv提供的静态链接库,位置如下图. 首先设置VS配置.有如下几个配置 1 工具->选项->项目和解决方案 ...
- 【LeetCode】36 - Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.(http://sudoku.com.au/TheRu ...
- javascript函数sort
sort函数用于对数组的元素进行排序 语法:arrayObject.sort(sortby); 参数sortby可选,规定排序顺序,必须是函数. 如果调用该方法时没有使用参数,将按照字幕顺序进行排序, ...
- air手势代码
//下列2句谁放上面谁生效要么触控生效,要么手势生效 Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT; Multitouch.inputM ...
- 【Visual Studio2010】创建XAML分析插件
最近项目[Silverlight]中的需要实现国际化,需要对所有控件进行一个处理.由于使用了Telerik的控件,只需要去掉原有的Label或者Header属性,然后添加一个资源Key即可.但是在项目 ...
- SQL获取变量类型以及变量最大长度
DECLARE @Temp nvarchar(1050)='' SELECT CAST(SQL_VARIANT_PROPERTY(@Temp, 'BaseType') AS VARCHAR(50))S ...
- JQ避免出现多次执行一个事件的解决方案
点击按钮之后会多次执行一个事件的话,就在方法结尾加入如下代码,这样的话事件就可以只执行一次了 //避免出现多次执行事件的问题 event.stopPropagation(); 此外,时间的重复绑定也有 ...