import heapq num = int(input().strip()) result = [] for i in range(num): temp = [int(x) for x in input().strip().split(' ')] if temp[0]<3: result.append(0) else: res = [] tp = [] temp = temp[1:] temp.sort() for x in temp: if x > 0: heapq.heappush(tp, -x) while(len(tp)>=3): x1 = heapq.heappop(tp) x2 = heapq.heappop(tp) x3 = heapq.heappop(tp) res.append(-x3) x1-=x3 x2-=x3 if x1<0: heapq.heappush(tp, x1) if x2<0: heapq.heappush(tp, x2) result.append(sum(res)) for x in result: print(x) 我们写的一样吧 我是0