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 ...
随机推荐
- 9-(基础入门篇)云端安装MQTT服务器
https://www.cnblogs.com/yangfengwu/p/9953703.html 记得把文件拷贝到上一节配置的和云端共享的那个盘里面,好拷贝文件到云服务器 进入到bin目录 咱先以控 ...
- SQL Server中使用convert进行日期转换(转载)
一般存入数据库中的时间格式为yyyy-mm-dd hh:mm:ss 如果要转换为yyyy-mm-dd 短日期格式.可以使用convert函数.下面是sqlserver帮助中关于convert函数的声 ...
- 如何学习 Webpack
webpack-howto Tip: 本文是 webpack-howto 的原文,我觉得这篇文章写得非常好,确实算是目前学习 webpack 入门的必读文章.直接收录之. 本教程的目标 这是一本教你如 ...
- .NET开发微信小程序-生成二维码 - 转
1.生成小程序二维码功能 直接请求相应的链接.传递相应的参数 以生成商铺的付款码为例: var shopsId = e.ShopsId //付款码的参数 var codeModel = new fun ...
- MVC ActionResult派生类关系图
态度决定一切,我要改变的不仅仅是技术,还有对待事情的态度! 先上个图: 由上图可知,ActionResult为根节点,其下有很多子节点!下面简单介绍下: MVC中ActionResult是Action ...
- C# 枚举基本用法及扩展方法
没什么好说的,都是些基础! 代码如下: using System; using System.Collections.Generic; using System.ComponentModel; usi ...
- 机器学习 第四篇:OLS回归分析
变量之间存在着相关关系,比如,人的身高和体重之间存在着关系,一般来说,人高一些,体重要重一些,身高和体重之间存在的是不确定性的相关关系.回归分析是研究相关关系的一种数学工具,它能帮助我们从一个变量的取 ...
- memcached程序端口监控脚本
线上memcached服务器启动了很多实例,端口很多,需要对这些端口进行监控,并在端口关闭的情况下自启动.监控脚本如下: [root@memcache2 ~]# ps -ef|grep /usr/bi ...
- Python 工程管理及 virtualenv 的迁移
virtualenv 是管理 python 工程的利器,它可以很好的帮你维护项目中的依赖,使用 virtualenv,还能保持 global 库的干净.不会被不同项目中的第三方库所污染. virtua ...
- 【2015 软件工程 个人项目 PJ1】四则运算题目生成程序
1.开发时间预估 PSP2.1 Personal Software Process Stages Time Planning 计划 · Estimate · 估计这个任务需要多少时间 2day Dev ...