Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- def len1(L):
- return(len(L))
- N,M = map(int,input().split())
- V = [int(i) for i in input().split()]
- B = [int(i) for i in input().split()]
- V1 = dict()
- for i in range(len(V)):
- if V[i] not in V1:
- V1[V[i]] = []
- V1[V[i]].append({i})
- if i != 0:
- for i1 in list(V1):
- if i1 + V[i] not in V1:
- V1[V[i] + i1] = []
- if len(V1[i1]) == 0:
- del V1[i1]
- else:
- tmp = sorted(V1[i1],key = len1)[0]
- g = 0
- for i2 in tmp:
- g += V[i2]
- if V[i] + g == V[i] + i1 and g != V[i]:
- V1[V[i] + i1].append({i,*tmp})
- del tmp
- B1 = dict()
- for i in range(len(B)):
- if B[i] not in B1:
- B1[B[i]] = []
- B1[B[i]].append({i})
- if i != 0:
- for i1 in list(B1):
- if i1 + B[i] not in B1:
- B1[B[i] + i1] = []
- if len(B1[i1]) == 0:
- del B1[i1]
- else:
- tmp = sorted(B1[i1], key=len1)[0]
- g = 0
- for i2 in tmp:
- g += B[i2]
- if B[i] + g == B[i] + i1 and g != B[i]:
- B1[B[i] + i1].append({i, *tmp})
- del tmp
- while len(V1) != 0 and len(B1) != 0:
- a = set(V1) & set(B1)
- if len(a) == 0:
- print(0)
- return
- a = max(a)
- if len(V1[a]) != 0 and len(B1[a]) != 0:
- break
- del V1[a]
- del B1[a]
- print(a)
- print(len(V1[a][0]))
- for i in V1[a][0]:
- print(i + 1,end = ' ')
- print(end = '\n')
- print(len(B1[a][0]))
- for i in B1[a][0]:
- print(i + 1,end = ' ')
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement