记录编号 100026 评测结果 AAAAAAAAAA
题目名称 [网络流24题] 负载平衡 最终得分 100
用户昵称 GravatarOI永别 是否通过 通过
代码语言 C++ 运行时间 0.003 s
提交时间 2014-05-02 20:06:38 内存使用 0.28 MiB
显示代码纯文本
  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<iostream>
  5. #include<vector>
  6. using namespace std;
  7.  
  8. vector <short> a,s;
  9. short n;
  10. short ave = 0;
  11.  
  12. inline short getshort(){
  13. char ch;
  14. short x = 0;
  15. while (!isdigit(ch = getchar()));
  16. x = ch - 48;
  17. while (isdigit(ch = getchar())) x = x * 10 + ch - 48;
  18. return x;
  19. }
  20. int main(){
  21. freopen("overload.in","r",stdin);
  22. freopen("overload.out","w",stdout);
  23. n = getshort();
  24. a.push_back(0);
  25. short x;
  26. for (short i = 1; i <= n; i ++){
  27. x = getshort();
  28. a.push_back(x);
  29. ave += x;
  30. }
  31. ave /= n;
  32. s.push_back(0);
  33. for (short i = 1; i < n; i++){
  34. s.push_back(s.at(i - 1) + a.at(i) - ave);
  35. }
  36. sort(s.begin()+1,s.end());
  37. short mid = s.at(n >> 1);
  38. short ans = abs(mid);
  39. for (short i = 1; i < n; i++)
  40. ans += abs(s.at(i) - mid);
  41. printf("%d\n",ans);
  42. return 0;
  43. }