Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. def main():
  2. def len1(L):
  3. return(len(L))
  4.  
  5. N,M = map(int,input().split())
  6. V = [int(i) for i in input().split()]
  7. B = [int(i) for i in input().split()]
  8. V1 = dict()
  9. for i in range(len(V)):
  10. if V[i] not in V1:
  11. V1[V[i]] = []
  12. V1[V[i]].append({i})
  13. if i != 0:
  14. for i1 in list(V1):
  15. if i1 + V[i] not in V1:
  16. V1[V[i] + i1] = []
  17. if len(V1[i1]) == 0:
  18. del V1[i1]
  19. else:
  20. tmp = sorted(V1[i1],key = len1)[0]
  21. g = 0
  22. for i2 in tmp:
  23. g += V[i2]
  24. if V[i] + g == V[i] + i1 and g != V[i]:
  25. V1[V[i] + i1].append({i,*tmp})
  26. del tmp
  27. B1 = dict()
  28. for i in range(len(B)):
  29. if B[i] not in B1:
  30. B1[B[i]] = []
  31. B1[B[i]].append({i})
  32. if i != 0:
  33. for i1 in list(B1):
  34. if i1 + B[i] not in B1:
  35. B1[B[i] + i1] = []
  36. if len(B1[i1]) == 0:
  37. del B1[i1]
  38. else:
  39. tmp = sorted(B1[i1], key=len1)[0]
  40. g = 0
  41. for i2 in tmp:
  42. g += B[i2]
  43. if B[i] + g == B[i] + i1 and g != B[i]:
  44. B1[B[i] + i1].append({i, *tmp})
  45. del tmp
  46. while len(V1) != 0 and len(B1) != 0:
  47. a = set(V1) & set(B1)
  48. if len(a) == 0:
  49. print(0)
  50. return
  51. a = max(a)
  52. if len(V1[a]) != 0 and len(B1[a]) != 0:
  53. break
  54. del V1[a]
  55. del B1[a]
  56. print(a)
  57. print(len(V1[a][0]))
  58. for i in V1[a][0]:
  59. print(i + 1,end = ' ')
  60. print(end = '\n')
  61. print(len(B1[a][0]))
  62. for i in B1[a][0]:
  63. print(i + 1,end = ' ')
  64. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement