Gym 100637F F. The Pool for Lucky Ones

时间:2022-03-29 00:42:57

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&period; 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 &Tab;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&period; Flood bfs

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

  5. Codeforces Gym 100513F F&period; Ilya Muromets 线段树

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

  6. Codeforces Gym 100513F F&period; Ilya Muromets 水题

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

  7. Gym - 100283F F&period; 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&comma; Grand Prix of Korea &lpar;Division 2&rpar; GYM 102058 F SG函数

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

  9. Gym 100952 F&period; Contestants Ranking

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

随机推荐

  1. 让游戏以高性能GPU(独立显卡)运行

    在EXE中导出全局变量: N卡: extern "C" { __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001 ...

  2. JVM&sol;JDK&sol;JRE&sol;IDE—区别(很经典)

    转载于 http://blog.csdn.net/jojo52013145/article/details/5801916 只是为了学习,转载没有别的目地,就是爱copy,copy一点点,进步一点点 ...

  3. 01JavaIO详解&lowbar;File类

    对程序语言设计者来说,设计一个令人满意的I/O系统,是件极艰难的任务.——摘自Think in java 对java而言,File表示的是文件或目录.但是我们知道文件和目录是不一样的,文件里面存放的是 ...

  4. 【转】Android端与Android端利用WIFI进行FTP通信

    原文网址:http://www.cnblogs.com/zhangkai5157/p/4303188.html 一.客户端通信工具类: import java.io.File; import java ...

  5. HDU 5024 Wang Xifeng&&num;39&semi;s Little Plot(枚举)

    题意:求一个图中只有一个90°拐点的路的最大长度. 分析:枚举每一个为'.'的点,求出以该点为拐点的八种路中的最大长度,再比较所有点,得出最大长度即可. 如上样例,这样是个90°的角... 注意:最多 ...

  6. 《Genesis-3D开源游戏引擎完整实例教程-2D射击游戏篇04:碰撞检测》

    4.碰撞检测 碰撞概述: 游戏世界里,游戏对象不能做出如同在真实世界里的物理运动效果.对于大部分游戏来说,都要为其添加物理系统,让其可以模拟真实世界发生的物理运动.但是在这个打飞机游戏Demo中,是用 ...

  7. TableLaout

    <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=&quot ...

  8. ubuntu诸软件安装

    1060显卡驱动安装: sudo apt-get install nvidia-384 ss qt安装:sudo add-apt-repository ppa:hzwhuang/ss-qt5sudo ...

  9. 一则ORACLE进程都在但是无法进入实例的问题

    [oracle@localhost ~]$ ps -ef|grep smonoracle 14809 1 0 Sep25 ? 00:13:02 ora_smon_mailp3[oracle@local ...

  10. Qt——容器类(译)

    注:本文是我对Qt官方文档的翻译,错误之处还请指正. 原文链接:Container Classes 介绍 Qt库提供了一套通用的基于模板的容器类,可以用这些类存储指定类型的项.比如,你需要一个大小可变 ...