Gym 100637F F. The Pool for Lucky Ones violence

Source: Internet
Author: User

Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

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

Description

A new swimming pool has been built on Kazan for the forthcoming Water Sports World Championship. The pool Has  N  lanes. Some of the lanes is already occupied by swimmers. Tatar scientists has divided the lanes into the lucky and unlucky ones. The unlucky lanes is those with the maximum amount of swimmers. That's, there is no other lane where there would being more swimmers than on unlucky one. The unlucky lanes make swimmers unhappy. The rest of the lanes is considered to be lucky. The lucky lanes make people happy. The scientists took a decision to make more people happy. In order to does 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 is moved to the second lane, and the swimmer from the last lane ––to the E before last.

Input

The first line contains a 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

Test instructions

Swimming pool, with the largest number of waterways is not happy

You can move a person to an adjoining waterway and ask you the minimum number of unhappy people

Exercises

The brute force enumeration is good, the violence moves to the left and then to the right, and then to sweep again

Code

#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>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)Const intmaxn=202501;#defineMoD 1000000007#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************ll D[maxn];ll A[MAXN];intMain () {intn=read (); ll MAXN=0;  for(intI=1; i<=n;i++) {A[i]=read (); D[a[i]]++; MAXN=Max (maxn,a[i]); } ll ans=d[maxn]*MAXN;  for(intI=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(intj=maxn+ -;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(intj=maxn+ -;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;}

Gym 100637F F. The Pool for Lucky Ones violence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.