Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f = input().split()
- n, m = int(f[0]), int(f[1])
- s = input()
- allSet = set()
- a=[]
- for i in range(m):
- f = input().split()
- l, c = int(f[0]), int(f[1])
- word = input()
- cur = set(word)
- pair = (cur, c)
- a.append(pair)
- allSet = allSet.union(cur)
- s = s.replace('*', '')
- a = sorted(a, key=lambda x: x[1], reverse=False)
- needSet = set(s)
- # print(needSet)
- # print(allSet)
- if not needSet.issubset(allSet):
- print(-1)
- exit(0)
- k = 0
- for ch in s:
- for p in a:
- if ch in p[0]:
- k += p[1]
- print(k)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement