Run ID | Author | Problem | Lang | Verdict | Time | Memory | Code Length | Submit Time |
---|---|---|---|---|---|---|---|---|
36199 | Wangzyy | 石子 | C++ | Accepted | 0 MS | 248 KB | 525 | 2024-01-11 15:14:16 |
#include <bits/stdc++.h> using namespace std; int a[500], b[500]; int main(){ int n; cin >> n; int sum = 0; for(int i = 1; i <= n; i ++ ){ cin >> a[i]; a[i + n] = a[i]; sum += a[i]; } int ave = sum / n; int ans = 1 << 30; for(int i = 1; i <= n; i ++ ){ for(int j = 1; j <= n; j ++ ){ b[j] = a[j + i - 1]; } int res = 0; for(int j = 1; j <= n; j ++ ){ res += abs(b[j] - ave); b[j + 1] += b[j] - ave; } ans = std::min(ans, res); } cout << ans; return 0; }