思路
代码
#include <cstdio>
int n, na, nb, ans;
struct Node {
int a, b, c;
} aa[1005], bb[1005], tmp;
inline int read() {
int s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * f;
}
void qsortA(int L, int R, Node * arr) {
int l = L, r = R;
int mid = arr[l + r >> 1].a;
while (l < r) {
while (arr[l].a < mid) l++;
while (arr[r].a > mid) r--;
if (l <= r) {
tmp = arr[l];
arr[l] = arr[r];
arr[r] = tmp;
l++, r--;
}
}
if (l < R) qsortA(l, R, arr);
if (L < r) qsortA(L, r, arr);
}
void qsortB(int L, int R, Node * arr) {
int l = L, r = R;
int mid = arr[l + r >> 1].b;
while (l < r) {
while (arr[l].b > mid) l++;
while (arr[r].b < mid) r--;
if (l <= r) {
tmp = arr[l];
arr[l] = arr[r];
arr[r] = tmp;
l++, r--;
}
}
if (l < R) qsortB(l, R, arr);
if (L < r) qsortB(L, r, arr);
}
int main() {
n = read();
for (int i = 1; i <= n; ++i) aa[i].a = read();
for (int i = 1; i <= n; ++i) aa[i].b = read();
for (int i = 1; i <= n; ++i) {
if (aa[i].a < aa[i].b) {
aa[++na] = aa[i], aa[na].c = i;
} else {
bb[++nb] = aa[i], bb[nb].c = i;
}
}
qsortA(1, na, aa); qsortB(1, nb, bb);
for (int j = 1; j <= nb; ++j) aa[++na] = bb[j];
for (int i = 1, a = 0, b = 0; i <= na; ++i) {
a += aa[i].a;
if (ans < a) {
ans = a + aa[i].b;
} else {
ans += aa[i].b;
}
}
printf("%d
", ans);
for (int i = 1; i <= na; ++i) {
printf("%d", aa[i].c);
if (i != na) putchar(' ');
}
return 0;
}