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/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=202501;
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//**************************************************************************************


ll d[maxn];
ll a[maxn];

int main()
{
    int n=read();
    ll maxn=0;
    for(int i=1;i<=n;i++)
    {
        a[i]=read();
        d[a[i]]++;
        maxn=max(maxn,a[i]);
    }
    ll ans=d[maxn]*maxn;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==0)
            continue;
        if(i!=n)
        {
            d[a[i]]--;
            d[a[i]-1]++;
            d[a[i+1]+1]++;
            d[a[i+1]]--;
            for(int j=maxn+100;j>0;j--)
            {
                if(d[j]>0)
                {
                    ans=min(d[j]*j,ans);
                    break;
                }
            }
            d[a[i]]++;
            d[a[i]-1]--;
            d[a[i+1]+1]--;
            d[a[i+1]]++;
        }
        if(i!=1)
        {
            d[a[i]]--;
            d[a[i]-1]++;
            d[a[i-1]+1]++;
            d[a[i-1]]--;
            for(int j=maxn+100;j>0;j--)
            {
                if(d[j]>0)
                {
                    ans=min(d[j]*j,ans);
                    break;
                }
            }
            d[a[i]]++;
            d[a[i]-1]--;
            d[a[i-1]+1]--;
            d[a[i-1]]++;
        }
    }
    cout<<ans<<endl;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值