###### BZOJ 3293/1465/1045([Cqoi2011]分金币/糖果传递/[HAOI2008] 糖果传递-列方程)

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
ll a[400008],b[400008];
ll Abs(ll x){return (x<0)?(-x):(x);}
int main()
{
//  freopen("bzoj1045.in","r",stdin);
//  freopen(".out","w",stdout);
For(i,n) {
scanf("%lld",&a[i]);
s+=a[i];
}
s/=n;
b[0]=0; For(i,n) b[i]=b[i-1]+s-a[i];
sort(b+1,b+1+n);
ll t=0;
For(i,n) t+=Abs(b[i]-b[n/2+1]);
printf("%lld\n",t);
return 0;
}


#### 【BZOJ】1045 [HAOI2008] 糖果传递 && 3293 [Cqoi2011]分金币 贪心

2017-07-03 09:36:18

#### 【BZOJ 3293】 [Cqoi2011]分金币

2015-04-20 08:22:25

#### 1045: [HAOI2008]糖果传递/3293: [Cqoi2011]分金币

2017-04-02 18:51:21

#### 【bzoj 1045】糖果传递 & 【bzoj 1465】糖果传递 & 【bzoj 3293】分金币 （乱搞）

2018-01-07 09:05:19

#### [BZOJ 1045] HAOI 2008 糖果传递 & [BZOJ 3293] CQOI 2011 分金币 · 数学

2015-05-02 09:39:48

#### BZOJ 1045/1465: [HAOI2008] 糖果传递

2017-03-07 10:54:25

#### BZOJ3293 [CQOI2011]分金币

2018-01-05 21:49:05

#### [HAOI2008][CQOI2011]糖果传递

2013-10-05 22:31:42

#### 3293: [Cqoi2011]分金币

2016-12-20 10:38:04

#### BZOJ[1465/1045]: 糖果传递

2016-08-09 16:16:04

## 不良信息举报

BZOJ 3293/1465/1045([Cqoi2011]分金币/糖果传递/[HAOI2008] 糖果传递-列方程)