fork(2) download
  1. local buildingsNum = io.read("*n")
  2. local buildings = {}
  3. local buildingNumberOrder = {}
  4. for i = 1, buildingsNum do
  5. local x, y, number, occupants = io.read("*n", "*n", "*n", "*n")
  6. buildings[{x, y, number, occupants}] = 0
  7. buildingNumberOrder[number] = i
  8. end
  9.  
  10. local bombings = io.read("*n")
  11. for i = 1, bombings do
  12. local x, y, radius = io.read("*n", "*n", "*n")
  13. local buildingsToEvacuate = {}
  14. local atLeastOne = false
  15. for building, _ in pairs(buildings) do
  16. if (x - building[1])^2 + (y - building[2])^2 <= radius * radius then
  17. table.insert(buildingsToEvacuate, building)
  18. atLeastOne = true
  19. end
  20. end
  21. local evacuated = 0
  22. local indexesToEvacuate = {}
  23. for _, building in ipairs(buildingsToEvacuate) do
  24. evacuated = evacuated + building[4]
  25. table.insert(indexesToEvacuate, building[3])
  26. buildings[building] = nil
  27. end
  28.  
  29. table.sort(indexesToEvacuate, function(a, b) return buildingNumberOrder[a] < buildingNumberOrder[b] end)
  30. for _, index in ipairs(indexesToEvacuate) do
  31. io.write(index, _ ~= #indexesToEvacuate and " " or "")
  32. end
  33. io.write(#indexesToEvacuate ~= 0 and "\n" or "")
  34. if not atLeastOne then
  35. io.write("NULL")
  36. else
  37. io.write(evacuated)
  38. end
  39. io.write("\n")
  40. end
Success #stdin #stdout 0s 5564KB
stdin
4
1 1 3 17
2 3 7 32
0 0 14 100
5 4 5 46
2
2 2 6
0 0 2
stdout
3 7 14 5
195
NULL