vector <int> getOrdering( vector <int> height, vector <int> bloom, vector <int> wilt )
{
int n = height.size();
vector <int> res (n);
vector <int> mark (n, 0);
int mini, ind;
bool b;
for (int i = n-1; i >= 0; i--)
{
ind = mini = 1001;
for (int j = 0; j < n; j++)
if (!mark[j])
{
b = true;
for (int k = 0; k < n; k++)
if (!mark[k] && height[k] > height[j] &&
( (bloom[j] >= bloom[k] && bloom[j] <= wilt[k]) || (bloom[k] >= bloom[j] && bloom[k] <= wilt[j]) )
)
{
b = false;
break;
}
if (b && height[j] < mini)
{
mini = height[j];
ind = j;
}
}
mark[ind] = 1;
res[i] = mini;
}
return res;
}
dmVjdG9yIDxpbnQ+IGdldE9yZGVyaW5nKCB2ZWN0b3IgPGludD4gaGVpZ2h0LCB2ZWN0b3IgPGludD4gYmxvb20sIHZlY3RvciA8aW50PiB3aWx0ICkgCnsKCWludCBuID0gaGVpZ2h0LnNpemUoKTsKCXZlY3RvciA8aW50PiByZXMgKG4pOwoJdmVjdG9yIDxpbnQ+IG1hcmsgKG4sIDApOwoJaW50IG1pbmksIGluZDsKCWJvb2wgYjsKCWZvciAoaW50IGkgPSBuLTE7IGkgPj0gMDsgaS0tKQoJewoJCWluZCA9IG1pbmkgPSAxMDAxOwoJCWZvciAoaW50IGogPSAwOyBqIDwgbjsgaisrKQoJCQlpZiAoIW1hcmtbal0pCgkJCXsKCQkJCWIgPSB0cnVlOwoJCQkJZm9yIChpbnQgayA9IDA7IGsgPCBuOyBrKyspCgkJCQkJaWYgKCFtYXJrW2tdICYmIGhlaWdodFtrXSA+IGhlaWdodFtqXSAmJgoJCQkJCQkoIChibG9vbVtqXSA+PSBibG9vbVtrXSAmJiBibG9vbVtqXSA8PSB3aWx0W2tdKSB8fCAoYmxvb21ba10gPj0gYmxvb21bal0gJiYgYmxvb21ba10gPD0gd2lsdFtqXSkgKQoJCQkJCSAgICApCgkJCQkJewoJCQkJCQliID0gZmFsc2U7CgkJCQkJCWJyZWFrOwoJCQkJCX0KCQkJCWlmIChiICYmIGhlaWdodFtqXSA8IG1pbmkpCgkJCQl7CgkJCQkJbWluaSA9IGhlaWdodFtqXTsKCQkJCQlpbmQgPSBqOwoJCQkJfQoJCQl9CgkJbWFya1tpbmRdID0gMTsKCQlyZXNbaV0gPSBtaW5pOwoJfQoJcmV0dXJuIHJlczsKfQ==