practivceAlgorithm/codeforce
[Codeforce][Python] #702 E. Accidental Victory
findTheValue
2021. 11. 7. 02:17
heap으로 값이 작은것부터 정렬 시킨 뒤 누적합과 내 값을 비교해가며 왕이될 수 있는 값을 구해갔습니다.
import sys
input = sys.stdin.readline
from heapq import heappop, heappush
for test in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
heap = []
for idx, num in enumerate(arr):
heappush(heap, (num, idx))
total, answer = 0, []
while heap:
num, idx = heappop(heap)
if total >= num:
answer.append(idx + 1)
else:
answer = [idx + 1]
total += num
answer.sort()
print(len(answer))
print(*answer)