/*
* 11300.cpp
*
* Created on: Dec 31, 2012
* Author: joker
*/
#define Main 1
#define INPUT_REDIRECT "11300.test"
#if Main
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int maxn = 1000000 + 10;
long long a[maxn];
long long c[maxn];
int main(int argc, char **argv) {
#ifndef ONLINE_JUDGE
freopen(INPUT_REDIRECT, "r", stdin);
#endif
int n;
while (scanf("%d", &n) != EOF) {
long long total = 0, tmp = 0;
long long m;
for (int i = 0; i < n; ++i) {
scanf("%lld", &tmp);
total += tmp;
a[i] = tmp;
}
m = total / n;
c[0] = 0;
for (int i = 1; i < n; ++i) {
c[i] = c[i - 1] + a[i] - m;
}
nth_element(c + 0, c + (n / 2), c + n);
long long x1 = c[n/2];
long long ans = 0;
for (int i = 0; i < n; ++i)
ans += abs(x1 - c[i]);
printf("%lld\n", ans);
}
return 0;
}
#endif
uva 11300 (代数分析)
最新推荐文章于 2020-05-09 10:17:40 发布