N, K = map(int, input().split()) data = {} for _ in range(N): c, p, d = input().split() data[c] = (p, int(d)) for _ in range(K): g, m, w = input().split() pin, save = data[g] if pin != m: continue data[g] = (pin, save - int(w)) for name, d in data.items(): print(name, d[1])

`class Solution { public int[] solution(int N, int[] A) { int[] res = new int[N]; int max = 0; int min = 0; for (int i = 0; i < A.length; i++) { int index = A[i] - 1; if (index < N) { if (res[index] < min) { res[index] = min; } res[index]++; if (res[index] > max) { max = res[index]; } } else { min = max; } } for (int i = 0; i < N; i++) { if (res[i] < min) { res[i] = min; } } return res; } }`