F. The Pool for Lucky Ones

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100637/problem/F

Description

A new swimming pool has been built in Kazan for the forthcoming Water Sports World Championship. The pool has N lanes. Some of the lanes are already occupied by swimmers. Tatar scientists have divided the lanes into the lucky and unlucky ones. The unlucky lanes are those with the maximum amount of swimmers. That is, there is no other lane where there would be more swimmers than on unlucky one. The unlucky lanes make swimmers unhappy. The rest of the lanes are considered to be lucky. The lucky lanes make people happy. The scientists took a decision to make more people happy. In order to do this they had an agreement with the pool manager saying they can move a single person from any lane to the one neighboring if it was necessary. The swimmer from the first lane can only be moved to the second lane, and the swimmer from the last lane –– to the one before last.

Input

The first line contains an integer N — the amount of lanes in the pool (3 ≤ N ≤ 105). The second line contains N integers pi separated with spaces, describing distribution of swimmers between the lanes where pi is the amount of swimmers on i-th lane (0 ≤ pi ≤ 105).

Output

Output a single number — minimal possible number of unhappy swimmers.

Sample Input

3
1 3 5

Sample Output

5

HINT

题意

泳池,人最多的不快乐,可以将一个人随意移动到相邻泳池,问不快乐的人最少是多少

题解:

我只能说考虑多种情况,暴力就好

代码

 #include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef __int64 ll;
using namespace std;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//**************************************************************************************
int hash[];
int n;
ll a[];
int main()
{ scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%I64d",&a[i]);
hash[a[i]]++;
}
ll maxx;
for(int i=; i>=; i--)
if(hash[i])
{
maxx=i;
break;
}
if(maxx==)
{
printf("0\n");
return ;
}
a[]=;
a[n+]=;
if(hash[maxx]!=)
{
ll ans=hash[maxx]*maxx;
for(int i=; i<=n; i++)
{
if(a[i]==maxx)
{
if(a[i+]||a[i-])
{
ans=min(ans,maxx+);
}
if(a[i+]<maxx-&&i+<=n)
{
ans=min((hash[maxx]-)*(maxx),ans);
//return 0;
}
if(a[i-]<maxx-&&i->=)
{
ans=min((hash[maxx]-)*(maxx),ans);
//return 0;
}
}
}
printf("%I64d\n",ans);
}
else
{
for(int i=; i<=n; i++)
{
if(a[i]==maxx)
{
if(a[i+]<maxx-&&i+<=n&&hash[maxx-]==)
{
printf("%I64d\n",maxx-);
return ;
}
if(a[i-]<maxx-&&i->=&&hash[maxx-]==)
{
printf("%I64d\n",maxx-);
return ;
}
}
}
printf("%I64d\n",maxx);
} return ;
}

Gym 100637F F. The Pool for Lucky Ones的更多相关文章

  1. Gym 100637F F. The Pool for Lucky Ones 暴力

    F. The Pool for Lucky Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

  2. CF Gym 100637F The Pool for Lucky Ones

    题意:给你一串非负整数,可以将一个非零数减1,加到相邻的数字上,要使其中所有最大数字的和最小. 题解:模拟可以过.也可以分析,可以要减少最大数字和,如果最大数字出现大于等于3次,可以把最大数字加一,或 ...

  3. codeforces Gym 100187F F - Doomsday 区间覆盖贪心

    F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...

  4. Codeforces gym 100685 F. Flood bfs

    F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...

  5. Codeforces Gym 100513F F. Ilya Muromets 线段树

    F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...

  6. Codeforces Gym 100513F F. Ilya Muromets 水题

    F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...

  7. Gym - 100283F F. Bakkar In The Army —— 二分

    题目链接:http://codeforces.com/gym/100283/problem/F F. Bakkar In The Army time limit per test 2 seconds ...

  8. 2018-2019 XIX Open Cup, Grand Prix of Korea (Division 2) GYM 102058 F SG函数

    http://codeforces.com/gym/102058/problem/F 题意:平面上n个点  两个人轮流在任意两个点之间连一条线但是不能和已有的线相交,先围成一个凸多边形的获胜,先手赢还 ...

  9. Gym 100952 F. Contestants Ranking

    http://codeforces.com/gym/100952/problem/F F. Contestants Ranking time limit per test 1 second memor ...

随机推荐

  1. 如何建立批处理文件(.bat或.cmd)

    如何建立批处理文件(.bat或.cmd) 建立批处理文件 批处理文件就是把多个dos命令放在一起. 批处理文件是无格式的文本文件,它包含一条或多条命令.它的文件扩展名为 .bat 或 .cmd.在命令 ...

  2. 标准库errno.h 查看错误代码编号,errno:4 与error:2

    log 里报错,errno:4   与errno:2 查了一下 errno.h   --------下文来自百度百科 errno 编辑 errno 是记录系统的最后一次错误代码.代码是一个int型的值 ...

  3. apache 配置多个虚拟主机

    修改文件:httd.conf 文件地址:D:\wamp\bin\apache\Apache2.2.21\conf #配置虚拟主机<VirtualHost 127.0.0.3:80>Serv ...

  4. Hadoop之伪分布环境搭建

    搭建伪分布环境 上传hadoop2.7.0编译后的包并解压到/zzy目录下 mkdir /zzy 解压 tar -zxvf hadoop.2.7.0.tar.gz -C /zzy     配置hado ...

  5. string,const char*,char*之间的相互转换

    1. string转const char* string s = "abc"; const char* c_s = s.c_str(); 2. const char*转string ...

  6. 转:github使用教程(重装系统后遇到问题该文章帮我解决了)

    github简单使用教程 时间:2012 年 5 月 29 日 6 条评论 分类:学习笔记 , 网络 , 软件 目录 1.注册账户以及创建仓库 2.安装客户端msysgit 3.配置Git 4.提交. ...

  7. 浅析django的abstract,proxy, managed

    django.db.models.Model 的 Meta参数 参数 类型 说明 继承 abstract boolean 是否建表 不继承,子类自动充值为默认值(False) managed bool ...

  8. Swap Two Nodes in Linked List

    Given a linked list and two values v1 and v2. Swap the two nodes in the linked list with values v1 a ...

  9. IDEA 14快捷键

    1.ctrl+alt+左箭头.右箭头:返回到上次浏览的代码处(相当于Eclipse的alt+左右箭头) 编辑类: Ctrl+Space 基本代码实例(类.方法.变量) Ctrl + Shift + S ...

  10. iOS 的UIWindow 类研究

    今日发现如果想做出漂亮的界面效果,就需要仔细研究一下UIWindow这个类.现在还不清楚为什么要有这么一个UIWindow类,它跟UIView的根本区别是什么?和Android中的什么类比较相像.先做 ...