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. 三个css3趣玩小试

    http://jsbin.com/semeh/8 请使用chrome打开 1.类似于网易新闻客户端的loading效果,左边的圆圈 2.发散式心跳效果,右边的圆圈 3.youtub上,搜索进度条效果, ...

  2. icon@font-face那些事

    http://files.cnblogs.com/files/LoveOrHate/font.rar @font-face { font-family: 'Glyphicons Regular'; s ...

  3. There are no interfaces on which a capture can be done.

    There are no interfaces on which a capture can be done. 今天启动了Wireshark 但是提示→There are no interfaces ...

  4. Rescue

    1039: Rescue Time Limit: 1 Sec  Memory Limit: 32 MBSubmit: 1320  Solved: 306 Description Angel was c ...

  5. Third scrum meeting - 2015/10/28

    在一天的工作中明显发现到,无法和网站开发团队进行交流会严重导致我们的进程拖延,所以我们在现有的情况下也把大家的goal初步完成了,我们也对代码规范进行了详细的讨论,以及UI的设计完成,所以整个团队都真 ...

  6. 在Android的webview中定做js的alert,confirm和prompt对话框的方法

    在Android的webview中定制js的alert,confirm和prompt对话框的方法 http://618119.com/archives/2010/12/20/199.html 1.首先 ...

  7. [Effective JavaScript 笔记]第42条:避免使用轻率的猴子补丁

    41条对违反抽象原则行为的讨论之后,下面聊一聊终极违例.由于对象共享原型,因此每一个对象都可以增加.删除或修改原型的属性.这个有争议的实践通常称为猴子补丁. 猴子补丁示例 猴子补丁的吸引力在于其强大. ...

  8. 第16章 使用Squid部署代理缓存服务

    章节概述: 本章节从代理缓存服务的工作原理开始讲起,让读者能够清晰理解正向代理(普通模式.透明模式)与反向代理的作用. 正确的使用Squid服务程序部署代理缓存服务可以有效提升访问静态资源的效率,降低 ...

  9. 如何让Ubuntu系统支持WebP图片格式

    本文主要向大家介绍如何让 Ubuntu 系统支持查看 WebP 图片格式,以及如何将 WebP 转为 JPEG 或 PNG 图片格式的方法. 什么是WebP图片 Google开发并推出 WebP 图片 ...

  10. PCA

    理论部分可以看斯坦福大学的那份讲义,通俗易懂:http://www.cnblogs.com/jerrylead/archive/2011/04/18/2020209.html opencv中有PCA这 ...