wa了
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> w(n), p(n), idx(n);
for (int i = 0; i < n; ++i)
cin >> w[i];
for (int i = 0; i < n; ++i)
{
cin >> p[i];
idx[i] = i + 1;
}
sort(idx.begin(), idx.end(), [&](int a, int b)
{
return 1LL * w[a - 1] * (10000 - p[b - 1]) < 1LL * w[b - 1] * (10000 - p[a - 1]);
});
bool possible = true;
long long st = 0,bfc = 1e18;
for (int i = 0; i < n; ++i) {
st += w[idx[i] - 1];
bfc = std::min(bfc, st + w[idx[i] - 1]);
if (p[idx[i] - 1] == 10000) {
possible = false;
}
}
if (!possible || bfc > 1e17)
cout << "Impossible" << std::endl;
else {
for (int i = 0; i < n; ++i)
cout << idx[i] << " ";
cout << endl;
}
return 0;
}