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