标签:view scan lld one sed while alt names algorithm
1. UVa 11300
我的代码:
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; long long C[1000010], M, a; int main() { int n; while (~scanf("%d", &n)) { C[0] = 0; for (int i = 1; i <= n; i++) { scanf("%lld", &a); C[i] = C[i-1]+a; } M = C[n]/n; for (int i = 1; i < n; i++) C[i] -= i*M; sort(C, C+n); long long ans = 0, x = C[n/2]; for (int i = 0; i < n; i++) ans += abs(x-C[i]); cout<<ans<<endl; } }
标签:view scan lld one sed while alt names algorithm
原文地址:http://www.cnblogs.com/hqxue/p/6618635.html