bzoj1045/COGS1314 HAOI2008 糖果 环形均分纸牌

就简单的均分下就好啦

 1 int n;
 2 
 3 int main() {
 4     freopen("candya.in","r",stdin);
 5     freopen("candya.out","w",stdout);
 6     scanf("%d",&n);
 7     ll sum=0;
 8     for(int i=1;i<=n;i++) {
 9         scanf("%lld",&a[i]);
10         sum+=a[i];
11     }
12     ll average=sum/n;
13     for(int i=1;i<=n;i++) a[i]-=average;
14     for(int i=1;i<=n;i++) S[i]=S[i-1]+a[i];
15     sort(S+1,S+n+1);
16     ll ans=0;
17     for(int i=1;i<=n;i++) ans+=abs(S[i]-S[(n+1)/2]);
18     cout<<ans<<endl;
19     return 0;
20 }
View Code

 

posted @ 2018-07-16 15:06  My_Girlfriends  阅读(132)  评论(0编辑  收藏  举报