def parse(inFile):
return (tuple(inFile.getInts()+[inFile.getInts()]))
def solve((N,W,L,rs)):
xs = [(rs[i],i) for i in xrange(N)]
xs.sort()
coords = [(-1,-1) for i in xrange(N)]
lhs = [(0,0),(0,L)]
for (r,i) in xs[::-1]:
for z in xrange(len(lhs)):
m = lhs[z]
if m[0] == 0 or (m[0] + r) <= W:
cx = 0 if (m[0] == 0) else (m[0] + r)
cy = 0 if (m[1] == 0) else (lhs[z - 1][1] + r)
if (cy > L):
print "BANG!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
return "oops"
coords[i] = (cx,cy)
z2 = z + 1
while (z2 < len(lhs)) and (lhs[z2][1] <= cy + r):
z2 += 1
lhs = [v for v in lhs if v[0] >= cx + r] + ([(cx+r,0)] if cy == 0 else []) + [(cx + r, cy + r)] + [v for v in lhs if v[1] > cy + r]
break
if (coords[i] == (-1,-1)):
print "BANG!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
return "oops"
return " ".join([str(d) for c in coords for d in c])
if __name__ == "__main__":
from GCJ import GCJ
GCJ(parse, solve, "/Users/lpebody/gcj/2012_2/b", "B").run()
ZGVmIHBhcnNlKGluRmlsZSk6CiAgICByZXR1cm4gKHR1cGxlKGluRmlsZS5nZXRJbnRzKCkrW2luRmlsZS5nZXRJbnRzKCldKSkKCmRlZiBzb2x2ZSgoTixXLEwscnMpKToKICAgIHhzID0gWyhyc1tpXSxpKSBmb3IgaSBpbiB4cmFuZ2UoTildCiAgICB4cy5zb3J0KCkKICAgIGNvb3JkcyA9IFsoLTEsLTEpIGZvciBpIGluIHhyYW5nZShOKV0KICAgIGxocyA9IFsoMCwwKSwoMCxMKV0KICAgIGZvciAocixpKSBpbiB4c1s6Oi0xXToKICAgICAgICBmb3IgeiBpbiB4cmFuZ2UobGVuKGxocykpOgogICAgICAgICAgICBtID0gbGhzW3pdCiAgICAgICAgICAgIGlmIG1bMF0gPT0gMCBvciAobVswXSArIHIpIDw9IFc6CiAgICAgICAgICAgICAgICBjeCA9IDAgaWYgKG1bMF0gPT0gMCkgZWxzZSAobVswXSArIHIpCiAgICAgICAgICAgICAgICBjeSA9IDAgaWYgKG1bMV0gPT0gMCkgZWxzZSAobGhzW3ogLSAxXVsxXSArIHIpCiAgICAgICAgICAgICAgICBpZiAoY3kgPiBMKToKICAgICAgICAgICAgICAgICAgICBwcmludCAiQkFORyEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhIgogICAgICAgICAgICAgICAgICAgIHJldHVybiAib29wcyIKICAgICAgICAgICAgICAgIGNvb3Jkc1tpXSA9IChjeCxjeSkKICAgICAgICAgICAgICAgIHoyID0geiArIDEKICAgICAgICAgICAgICAgIHdoaWxlICh6MiA8IGxlbihsaHMpKSBhbmQgKGxoc1t6Ml1bMV0gPD0gY3kgKyByKToKICAgICAgICAgICAgICAgICAgICB6MiArPSAxCiAgICAgICAgICAgICAgICBsaHMgPSBbdiBmb3IgdiBpbiBsaHMgaWYgdlswXSA+PSBjeCArIHJdICsgKFsoY3grciwwKV0gaWYgY3kgPT0gMCBlbHNlIFtdKSArIFsoY3ggKyByLCBjeSArIHIpXSArIFt2IGZvciB2IGluIGxocyBpZiB2WzFdID4gY3kgKyByXQogICAgICAgICAgICAgICAgYnJlYWsKICAgICAgICBpZiAoY29vcmRzW2ldID09ICgtMSwtMSkpOgogICAgICAgICAgICBwcmludCAiQkFORyEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEiCiAgICAgICAgICAgIHJldHVybiAib29wcyIKICAgIHJldHVybiAiICIuam9pbihbc3RyKGQpIGZvciBjIGluIGNvb3JkcyBmb3IgZCBpbiBjXSkKCmlmIF9fbmFtZV9fID09ICJfX21haW5fXyI6CiAgICBmcm9tIEdDSiBpbXBvcnQgR0NKCiAgICBHQ0oocGFyc2UsIHNvbHZlLCAiL1VzZXJzL2xwZWJvZHkvZ2NqLzIwMTJfMi9iIiwgIkIiKS5ydW4oKQoKICAgICAgICAgICAgCg==