nq1s788

Слежка за отрезками (долго)

Nov 10th, 2025
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. t = int(input())
  2. for _ in range(t):
  3.     n, m = map(int, input().split())
  4.     a = [0 for i in range(n)]
  5.     otr = []
  6.     for i in range(m):
  7.         x, y = map(int, input().split())
  8.         x -= 1
  9.         y -= 1
  10.         otr.append((x, y))
  11.     k = int(input())
  12.     f1 = 0
  13.     for i in range(k):
  14.         zap = int(input())
  15.         if f1:
  16.             continue
  17.         zap -= 1
  18.         a[zap] = 1
  19.         f = 0
  20.         for e in otr:
  21.             if sum(a[e[0]:e[1] + 1]) > (e[1] - e[0] + 1) / 2:
  22.                 f += 1
  23.         if f > 0:
  24.             print(i + 1)
  25.             f1 = 1
  26.     if f1 == 0:
  27.         print(-1)
  28.  
Advertisement
Add Comment
Please, Sign In to add comment