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 ...
随机推荐
- 如何利用Skyline的TerraExplorer Pro 6.5提供的API接口实现矢量图层数据的动态投影
Skyline 支持国内常见的地图投影坐标系,包括WGS84.Beijing54.西安80.2000坐标系等,也可以自定义坐标系,比如一些做过参数变换加密的坐标系等. <!DOCTYPE htm ...
- CF258D Little Elephant and Broken Sorting/AGC030D Inversion Sum 期望、DP
传送门--Codeforces 传送门--Atcoder 考虑逆序对的产生条件,是存在两个数\(i,j\)满足\(i < j,a_i > a_j\) 故设\(dp_{i,j}\)表示\(a ...
- Jmeter(三十四)_Beanshell解析并提取json响应
1:前置条件 将fastjson-1.2.49.jar包置于jmeter的lib目录下,并将该jar包添加到测试计划的Library中:否则会报:Typed variable declaration ...
- kill方法
删除磁盘上的文件. 语法 Kill 路径名 所需的_路径名_参数是一个字符串表达式,指定要删除的一个或多个文件名. _Pathname_可能包括驱动器和目录或文件夹. 例子删除当前路径下的TXT文档 ...
- centos下部署NTP时间服务器同步环境记录
1)服务端部署 安装所需软件包 [root@test ~]# yum -y install ntp ntpdate 服务端自己先手工同步一次时间. [root@test ~]# ntpdate ntp ...
- Java开发23种设计模式之禅
六大原则 23种设计模式: 总体来说设计模式分为三大类: *创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. *结构型模式,共七种:适配器模式.装饰器模式.代理模式.外 ...
- Reading Task 2 —— by12061154Joy
关于Silver Bullet: Brooks在“No Silver Bullet”主张并断言在未来的十年之内(从1986年文章发表后开始计算),不会有任何单一的软件工程上的突破,能够让程序设计的生产 ...
- 【M2】软件工程终期总结报告——阅读作业
PhylabWeb——阅读作业 问题回顾 提问博客地址:http://www.cnblogs.com/kibbon/p/4831104.html 尚待解决的问题: Alpha/Beta,ZBB/RC阶 ...
- 1.个人项目 Individual Project
https://github.com/sunlitao 一. 实验1通讯录管理系统 通讯录中的联系人包含以下信息项:姓名.手机.办公电话.家庭电话.电子邮箱.所在省市.工作单位.家庭住址,群组分类(亲 ...
- Linux养成笔记
教程来自慕课网@Tony老师的课程 Linux简介 Linux发展史 Andrew S. Tanenbaum为了给学生讲课,买了一个Unix操作系统,参考他开发了Minix,并开放代码作为大学研究,2 ...