Paste Search Dynamic
changeLineToIntArray
  1. import sys
  2. from sys import stdout, stderr, stdin
  3.  
  4. def changeLineToIntArray(line):
  5.     arr = line.split()
  6.     return [int(i) for i in arr]
  7.  
  8. def Solve(*args):
  9.     param = locals()['args']
  10.     params = [int(i) for i in list(param)]
  11.     N = params[0]
  12.     L = params[1]
  13.     W = params[2]
  14.     sprinkles = params[3]
  15.     print(params)
  16.     # Lakukan Proses kalian disini
  17.     # Bla bla bla . . .
  18.     arr = []
  19.     for i in range(N):
  20.         if sprinkles[i][1] * 2 > W:
  21.             dx = sqrt((sprinkles[i][1]**2) - (W/2)**2)
  22.             arr += [[(sprinkles[i][0]-dx),(sprinkles[i][0]+dx)]]
  23.     print(arr)
  24.     c,i,lo = (0,)*3
  25.     while true:
  26.         furthest = -1
  27.         while i < len(arr) and arr[i][0] <= lo:
  28.             furthest = max(furthest, arr[i][1])
  29.             i += 1
  30.         if furthest == -1:
  31.             return -1
  32.         c += 1
  33.         lo = furthest
  34.         if lo >= L:
  35.             return c    
  36.  
  37. def main():
  38.     try:
  39.         while(true):
  40.             firstLine = next(inp).strip()
  41.             N, L, W = changeLineToIntArray(firstLine)
  42.  
  43.             sprinklers = []
  44.             for i in range(N):
  45.                 sprinkler = next(inp).strip()
  46.                 p, r = changeLineToIntArray(sprinkler)
  47.  
  48.                 sprinklers.append((p,r))
  49.             print(Solve(N,L,W, sprinklers))
  50.     except:
  51.         pass
  52.  
  53. # Mengambil semua input
  54. inp = iter(stdin.readlines())
  55. # Keluar dari Readlines tekan <Ctrl-D>
  56.  
  57. if __name__ == '__main__':
  58.     main()
  59.  
Parsed in 0.011 seconds