''' # 第一次尝试, ''->加n-k个-> 过10% ''' # 选择移除K个字母, 要使留下来的字符串字典序最小 # s = input().strip() # n = int(input().strip()) # fans = s # def dfs(ans, index, depth): # global fans # if index >= len(s): return # if depth > n: return # if depth == n: # if ans <= fans: # fans = ans # print(ans + s[index]) # dfs(ans + s[index], index+1, depth + 1) # dfs(ans, index+1, depth) # dfs('', 0, 0) # print(fans)
''' 当时dfs('', 0, 0)的写法报了点错, 以为不能这么写, 于是换成s中去k个 ''' # s = input().strip() # sz = len(s) # n = int(input().strip()) # fans = ''.join('z' for i in range(sz)) # def dfs(ans, index, depth): # global fans # if index >= sz: return # if depth == n: # if ans <= fans: # fans = ans # # print(ans[0:index] + ans[index+1:]) # dfs(ans[0:index] + ans[index+1:], index+1, depth + 1) # dfs(ans, index+1, depth) # dfs(s, 0, 0) # print(fans)
''' 第三次尝试, 重新接回第一种到n-k个数时结束的写法. 考完以后写出来的. 但不知道能不能过全部样例 ''' s = input().strip() sz = len(s) n = int(input().strip())
fans = ''.join('z'for i in range(sz)) # 初始化为最大
defdfs(ans, index): global fans if index == sz: return if len(ans) == sz-n: # print(ans, fans, ans <= fans) if ans <= fans: fans = ans dfs(ans + s[index], index+1) dfs(ans, index+1)
odict = dict() n = int(input().strip()) for i in range(n): ids, val = map(int, input().split()) odict[ids] = odict.setdefault(ids, 0) + val slist = sorted(odict.items(), key= lambda d: d[0], reverse=True) for k, v in odict.items(): print(k, v)