标签:
/*
题意:给你一个序列经过最小变换,变换一次为一个数+1,一个数-1,使得最大值与最小值相差1;
思路:与最后得到的序列相差的sum/2;
*/
#include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> using namespace std; #define ll __int64 #define mod 1000000007 int scan() { int res = 0 , ch ; while( !( ( ch = getchar() ) >= ‘0‘ && ch <= ‘9‘ ) ) { if( ch == EOF ) return 1 << 30 ; } res = ch - ‘0‘ ; while( ( ch = getchar() ) >= ‘0‘ && ch <= ‘9‘ ) res = res * 10 + ( ch - ‘0‘ ) ; return res ; } ll a[100010]; int main() { ll x,y,z,i,t; scanf("%I64d",&x); ll sum=0; for(i=0;i<x;i++) { scanf("%I64d",&a[i]); sum+=a[i]; } ll yu=sum%x; ll c=sum/x; ll cha=0;sort(a,a+x); for(i=x-1;i>=0;i--) { if(yu) cha+=abs(a[i]-c-1),yu--; else cha+=abs(a[i]-c); } printf("%I64d\n",cha/2); return 0; }
第一发。。。codeforces 609 C Load Balancing 贪心
标签:
原文地址:http://www.cnblogs.com/jhz033/p/5297242.html