parent
044e661e26
commit
c5feb2d388
@ -1,41 +1,10 @@
|
|||||||
#include <bits/stdc++.h>
|
#include <bits/stdc++.h>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
const int N = 10010;
|
|
||||||
int a[N];
|
|
||||||
int sum, avg, total;
|
|
||||||
int main() {
|
int main() {
|
||||||
int n;
|
string a = "abcdefg";
|
||||||
cin >> n;
|
|
||||||
for (int i = 1; i <= n; i++) {
|
|
||||||
cin >> a[i];
|
|
||||||
sum += a[i];
|
|
||||||
}
|
|
||||||
if (sum % n) {
|
|
||||||
cout << -1 << endl;
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
avg = sum / n;
|
|
||||||
|
|
||||||
for (int i = 1; i <= n; i++) {
|
cout << a.substr(1, 1) << endl; // a[1]
|
||||||
int d = a[i] - avg;
|
cout << a.substr(1, 3) << endl; // a[1] a[2] a[3]
|
||||||
total += abs(d);
|
cout << a.substr(0, 4) << endl;
|
||||||
for (int j = 1 + i; j <= n; j++) {
|
|
||||||
if (d > 0 && a[j] < avg) {
|
|
||||||
int x = min(d, avg - a[j]);
|
|
||||||
a[i] -= x;
|
|
||||||
a[j] += x;
|
|
||||||
d -= x;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (d < 0 && a[j] > avg) {
|
|
||||||
int x = min(d, a[j]-avg);
|
|
||||||
a[i] += x;
|
|
||||||
a[j] -= x;
|
|
||||||
d += x;
|
|
||||||
}
|
|
||||||
if (d == 0) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cout << total << endl;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in new issue