'Round 2022 A Kickstarter h-index off values
I am trying to do the Round A 2022 Kick Starter it seems that my values give an off by 1. Not sure if answer is related to h-index or current citation.
t = int(input())
print(t)
for i in range(t):
n = int(input())
print(n)
h_index=0
priority=[]
for elem in input().split():
if int(elem)>h_index:
priority.append(int(elem))
while True:
for x in priority:
if x<=h_index:
priority.pop(x)
if len(priority)>h_index+1:
h_index+=1
else:
break
print(h_index)
Example input:
2
3
5 1 2
6
1 3 3 2 2 15
Outputs:
0 1 2
0 1 2 2 2 2
Expected:
Case #1: 1 1 2
Case #2: 1 1 2 2 2 3
Analysis:
For test set 2, we initialize the H-index with 0, and after adding each paper, we need to update the current H-index. We can use a minimum priority queue data structure to store the citation numbers. As we go through each of the papers, we keep updating the current H-index. We also keep updating the priority queue so that it only contains numbers greater than the current H-index and remove the rest. For each new paper, we can follow these steps:
If the current citation number is bigger than the current answer, add it in the priority queue
Remove all the citation numbers from the priority queue which are not greater than the current answer
If the size of priority queue is not less than the current answer + 1, increment the current answer by 1 and return to step 2
Fixed:
t = int(input())
#print(t)
for i in range(t):
n = int(input())
#print(n)
h_index=0
priority=[]
for elem in input().split():
if int(elem)>h_index:
priority.append(int(elem))
while True:
#print(priority)
priority=[x for x in priority if x > h_index]
if len(priority)>(h_index+1):
h_index+=1
else:
break
print(len(priority))
Outputs:
1 1 2
1 1 2 2 2 3
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
