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 maxi, ind;
bool b;
for (int i = 0; i < n; i++)
{
ind = maxi = -1;
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[k] >= bloom[j] && bloom[k] <= wilt[j]) || (bloom[j] >= bloom[k] && bloom[j] <= wilt[k]) )
)
{
b = false;
break;
}
if (b && height[j] > maxi)
{
maxi = height[j];
ind = j;
}
}
mark[ind] = 1;
res[i] = maxi;
}
return res;
}
dmVjdG9yIDxpbnQ+IGdldE9yZGVyaW5nKCB2ZWN0b3IgPGludD4gaGVpZ2h0LCB2ZWN0b3IgPGludD4gYmxvb20sIHZlY3RvciA8aW50PiB3aWx0ICkgCnsKCWludCBuID0gaGVpZ2h0LnNpemUoKTsKCXZlY3RvciA8aW50PiByZXMgKG4pOwoJdmVjdG9yIDxpbnQ+IG1hcmsgKG4sIDApOwoJaW50IG1heGksIGluZDsKCWJvb2wgYjsKCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQoJewoJCWluZCA9IG1heGkgPSAtMTsKCQlmb3IgKGludCBqID0gMDsgaiA8IG47IGorKykKCQkJaWYgKCFtYXJrW2pdKQoJCQl7CQoJCQkJYiA9IHRydWU7CgkJCQlmb3IgKGludCBrID0gMDsgayA8IG47IGsrKykKCQkJCQlpZiAoIW1hcmtba10gJiYgaGVpZ2h0W2tdIDwgaGVpZ2h0W2pdICYmIAoJCQkJCQkoIChibG9vbVtrXSA+PSBibG9vbVtqXSAmJiBibG9vbVtrXSA8PSB3aWx0W2pdKSB8fCAoYmxvb21bal0gPj0gYmxvb21ba10gJiYgYmxvb21bal0gPD0gd2lsdFtrXSkgKSAKCQkJCQkgICAgKQoJCQkJCXsKCQkJCQkJYiA9IGZhbHNlOwoJCQkJCQlicmVhazsKCQkJCQl9CgkJCQlpZiAoYiAmJiBoZWlnaHRbal0gPiBtYXhpKQoJCQkJewoJCQkJCW1heGkgPSBoZWlnaHRbal07CgkJCQkJaW5kID0gajsKCQkJCX0KCQkJfQoJCW1hcmtbaW5kXSA9IDE7CgkJcmVzW2ldID0gbWF4aTsKCX0KCXJldHVybiByZXM7Cn0=