1 条题解

  • 0
    @ 2025-10-12 16:24:35

    #include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> #define pb push_back #define rep(a, b, c, d) for(int a=b; a<=c; a+=d) const int N = 1e6 + 5; int n, a[N], s[N]; signed main () { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; int pj = 0; for(int i = 1; i <= n; ++ i) cin >> a[i], pj += a[i]; pj /= n; for(int i = 1; i <= n; ++ i) a[i] -= pj, s[i] = s[i - 1] + a[i]; stable_sort(s + 1, s + n + 1); int ans = 0; for(int i = 1; i <= n; ++ i) ans += abs(s[n / 2 + 1] - s[i]); cout << ans; return 0; }

    信息

    ID
    17096
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者