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

时间:2022-09-30 11:47:24

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 long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
const int maxn=;
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
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;
}
//************************************************************************************** ll d[maxn];
ll a[maxn]; int main()
{
int n=read();
ll maxn=;
for(int i=;i<=n;i++)
{
a[i]=read();
d[a[i]]++;
maxn=max(maxn,a[i]);
}
ll ans=d[maxn]*maxn;
for(int i=;i<=n;i++)
{
if(a[i]==)
continue;
if(i!=n)
{
d[a[i]]--;
d[a[i]-]++;
d[a[i+]+]++;
d[a[i+]]--;
for(int j=maxn+;j>;j--)
{
if(d[j]>)
{
ans=min(d[j]*j,ans);
break;
}
}
d[a[i]]++;
d[a[i]-]--;
d[a[i+]+]--;
d[a[i+]]++;
}
if(i!=)
{
d[a[i]]--;
d[a[i]-]++;
d[a[i-]+]++;
d[a[i-]]--;
for(int j=maxn+;j>;j--)
{
if(d[j]>)
{
ans=min(d[j]*j,ans);
break;
}
}
d[a[i]]++;
d[a[i]-]--;
d[a[i-]+]--;
d[a[i-]]++;
}
}
cout<<ans<<endl;
}

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. hdu 3695 10 福州 现场 F - Computer Virus on Planet Pandora 暴力 ac自动机 难度&colon;1

    F - Computer Virus on Planet Pandora Time Limit:2000MS     Memory Limit:128000KB     64bit IO Format ...

  3. CF Gym 100637F &Tab;The Pool for Lucky Ones

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

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

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

  5. Codeforces gym 100685 F&period; Flood bfs

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

  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. Codeforces Gym 100513F F&period; Ilya Muromets 水题

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

  8. 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 ...

  9. 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个点  两个人轮流在任意两个点之间连一条线但是不能和已有的线相交,先围成一个凸多边形的获胜,先手赢还 ...

随机推荐

  1. hoj 2634 How to earn more

    有m个项目和n个员工,做项目i可以获得Ai元,但是必须雇用若干指定的员工.雇用员工j需要Bj元,一旦雇用便可以参与多个项目.问最大收益. 1<=M,N<=100. 最小割. 源点向每个项目 ...

  2. WPF重写Image实现动态图片--未测试

    WPF很强大,但是当WPF的image控件遇到gif时就只读了图片的第一帧,很好很强大! WPF不屑于gif的简单动画! 幸好WPF里有MediaElement这个东西,它是对MediaPlyer的一 ...

  3. CVTE实习面经

    一个月的实习都结束了,我才把这篇面经放出来...可能有记得不太清楚的地方,还请多多见谅. 第一次面试是在5月中旬. 这次面试问的主要是基础的问题吧,就是C和C++的基础问题,我记得有问到下面几个问题 ...

  4. Objective-C学习备忘录:Clang编译器编译运行Objective-C代码

    我们都知道可以通过Apple公司的Xcode工具来学习Objective-C编程语言,但是能不能脱离XCode这个IDE进行Objective-C学习呢?当然是可以的.首先作为计算机科班出身的程序员都 ...

  5. Android概述

  6. 框架中的HTML DOM Event 对象

    js中的this上下文会因事件而转换成html dom对象. 所以就有这样获取当前触发事件的dom对象: window.event.srcElement || window.event.target; ...

  7. IntelliJ IDEA 开发scala

    1.下载安装IntelliJ IDEA,并安装scala插件 我下载的是linux的13版本,linux版本是绿色版本,有一个启动的脚本,运行就可以了,也可以在linux建立快捷方式.windows的 ...

  8. dojo省份地市级联之地市封装类(二)

    dojo省份地市级联之地市封装类 City.java: /** * 地市封装类 */ package com.you.model; import java.io.Serializable; /** * ...

  9. 云计算---openstack实例共享80、443端口

    前言 因为openstack使用的是apache,所以不能共享80端口,但创建的许多云主机,虽然可以通过rinetd进行跳转,但有时需要直接访问80端口,所以这里我们选择包含了nginx的openre ...

  10. 输入流IS和输出流OS学习总结

    1.我们编写的程序,除了自身会定义一些数据信息外,经常还会引用外界的数据,或是将自身的数据发送到外界,比如我们编写的程序想读取一个文本文件, 又或者是我们想将程序的一些数据写到一个文件中,这时我们就要 ...