Codeforces Round #337 (Div. 2) B. Vika and Squares
2 seconds
256 megabytes
standard input
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.
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.
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.
5
2 4 2 3 3
12
3
5 5 5
15
6
10 10 10 1 10 10
11
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的更多相关文章
- 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 ...
- 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) 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 #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 ...
- Codeforces Round #337 (Div. 2) C. Harmony Analysis 构造
C. Harmony Analysis 题目连接: http://www.codeforces.com/contest/610/problem/C Description The semester i ...
随机推荐
- 如何屏蔽SkylineGlobe提供的三维地图控件上的快捷键
SkyllineGlobe提供的 <OBJECT ID=" TerraExplorer3DWindow" CLASSID="CLSID:3a4f9192-65a8- ...
- you-get帮助使用手册
you-get使用手册 可选参数: -V, --version 查看版本并退出 -h, --help 查看帮助信息 不影响使用的选项: -i, - ...
- WPF-利用Blend写的平面控制闸门开关动画
原文:WPF-利用Blend写的平面控制闸门开关动画 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/yangyisen0713/article/de ...
- 来不及说什么了,Python 运维开发剁手价仅剩最后 2 天
51reboot 运维开发又双叒叕的搞活动了—— Python 运维开发 18 天训练营课程, 剁手价1299 最后2天 上课方式:网络直播/面授(仅限北京) DAY1 - DAY4 Python3 ...
- VMware/KVM/OpenStack虚拟化之网络模式总结
一.VMware虚拟机网络模式 Vmware虚拟机有三种网络模式:Bridged (桥接模式).NAT (网络地址转换模式).Host-Only (仅主机模式).下面分别总结下这三种网络模式: 1. ...
- Dijkstra及其堆优化
朴素Dijkstra #include<bits/stdc++.h> using namespace std; const int inf=9999999; bool book[105]; ...
- 个人阅读作业2:结合《No Silver Bullet》谈谈我在软件开发过程的遇到的困难与体会
英文捉急,只能挑一段看得比较懂的,而且正好和我们现在编程任务联系比较紧密的内容来谈一谈体会. 在<No Silver Bullet>中,作者描述了造成软件本质性困难(essence)的四个 ...
- 【读书笔记】Linux内核设计与实现(第三章)
3.1 进程 处于执行期的程序. 进程就是正在执行的程序代码的实时结果.内核需要有效而又透明地管理所有细节. 执行线程(简称线程):在进程中活动的对象.每个线程都拥有一个独立的程序计数器.进程栈和一组 ...
- <<浪潮之巅>>阅读笔记一
第一次的阅读就想读这本书的,却因为很多愿意一直拖到现在,因为听说这本书在李开复先生 的微博上有推荐,更是增加了我的阅读兴趣.可能是因为在网上找的电子版的原因,通篇阅读的速度很快,但是没有纸质数那种细嚼 ...
- answer my questions from the book<构建之法>.
1)何为文档:文档时在一个项目进行的一生中所有记忆的集合.有需求分析.功能设计.在实现功能过程中也可以有一系列文档记录.测试文档等等. 2)结对工作等找队友会花费大量时间致耽误项目否:正如老师所讲,从 ...