Codeforces Round #337 (Div. 2) 610B 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, 3and
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.
题目链接:点击打开链接
给出n种油漆及每种油漆数量, 要求在长方形纸上挨个涂色, 从随意颜色開始涂, 问最多能够涂多少.
找到数量最小的, 求出数量最少的个数, 若数量为n, 则所有能够涂, 若数量为1, 则从下一个開始涂, 其它情况则求出最长的间隔.
AC代码:
- #include "iostream"
- #include "cstdio"
- #include "cstring"
- #include "algorithm"
- #include "queue"
- #include "stack"
- #include "cmath"
- #include "utility"
- #include "map"
- #include "set"
- #include "vector"
- #include "list"
- #include "string"
- #include "cstdlib"
- using namespace std;
- typedef long long ll;
- const int MOD = 1e9 + 7;
- const int INF = 0x3f3f3f3f;
- const int MAXN = 2e5 + 5;
- ll n, num, len, tmp, cnt, a[MAXN];
- int main(int argc, char const *argv[])
- {
- scanf("%lld", &n);
- for(int i = 1; i <= n; ++i)
- scanf("%lld", &a[i]);
- ll mi = INF;
- for(int i = 1; i <= n; ++i)
- mi = min(mi, a[i]);
- for(int i = 1; i <= n; ++i)
- if(a[i] == mi) num++;
- if(num == n) printf("%lld\n", n * a[1]);
- else if(num == 1) printf("%lld\n", n * mi + n - 1);
- else {
- for(int i = 1; i <= n; ++i) {
- if(a[i] == mi) {
- if(tmp > len) len = tmp;
- tmp = 0;
- }
- else tmp++;
- }
- for(int i = 1; i <= n; ++i)
- if(a[i] == mi) break;
- else cnt++;
- len = max(cnt + tmp, len);
- printf("%lld\n", n * mi + len);
- }
- return 0;
- }
Codeforces Round #337 (Div. 2) 610B 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) 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) 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 ...
随机推荐
- CAD绘制固定圆形云线标注(网页吧)
js中实现代码说明: function DoCloudCircleCommentFix() { var comment = mxOcx.NewEntity("IMxDrawComment&q ...
- Java B
3.继承时候类的执行顺序问题,一般都是选择题,问你将会打印出什么? 答:父类: package test; public class FatherClass { public FatherClass( ...
- 初始化react项目
react脚手架 npm install -g create-react-app 国内npm一般下载比较慢或者是常出现下载失败的情况,我们可以指定下载的仓库: npm install -g creat ...
- BZOJ 4695 最假女选手 线段树
题意: 给定一个长度为 N序列,编号从1 到 N.要求支持下面几种操作: 1.给一个区间[L,R] 加上一个数x 2.把一个区间[L,R] 里小于x 的数变成x 3.把一个区间[L,R] 里大于x ...
- [HNOI/AHOI2018]转盘(线段树优化单调)
gugu bz lei了lei了,事独流体毒瘤题 一句话题意:任选一个点开始,每个时刻向前走一步或者站着不动 问实现每一个点都在$T_i$之后被访问到的最短时间 Step 1 该题可证: 最优方案必 ...
- C语言标准库函数总结
一.动态内存分配1.malloc 原型:extern void *malloc(unsigned int num_bytes); 用法:#include <alloc.h> 功能:分 ...
- PHP:GD库 生成验证码图片
文章来源:http://www.cnblogs.com/hello-tl/p/7592998.html <?php /** * __construct($new):构造函数创建一张图片$new- ...
- ORM之连表操作
ORM之连表操作 -----------------------------连表的正向操作------------------------- 在models.py中创建两张表UserType和User ...
- FreeRTOS--疑难杂症
花了3个晚上,把这个章节看完,受益匪浅. 最有用的应该是与中断相关的错误,优先排查中断优先级设置. 堆栈溢出检查,可能用到,一般先把堆栈设置的足够大,只要没有溢出就是好事,溢出了,掌握了栈溢出钩子函数 ...
- Apollo源码解析看一文就够
对于配置中心我们先抛出问号三连,什么是配置中心?为什么要用配置中心?配置中心怎么用? 笔者说说自己理解的配置中心,个人观点的十六字 消息存储 消息推送 环境隔离 灰度发布 今天我们先来看Apollo配 ...