fork 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 math.sqrt((x - building[1])^2 + (y - building[2])^2) <= 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. table.sort(indexesToEvacuate, function(a, b) return buildingNumberOrder[a] < buildingNumberOrder[b] end)
  29. for _, index in ipairs(indexesToEvacuate) do
  30. io.write(index, " ")
  31. end
  32. io.write(#indexesToEvacuate ~= 0 and "\n" or "")
  33. if not atLeastOne then
  34. io.write("NULL")
  35. else
  36. io.write(evacuated)
  37. end
  38. io.write("\n")
  39. end
Success #stdin #stdout 0s 5328KB
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