My issue
in my code hidden case is not running please give correct code to run the program
My code
def count_boasting_students(N, scores):
# Sort the scores
sorted_scores = sorted(scores)
# Calculate the threshold
threshold = N // 2
count = 0
# Calculate the number of students who will boast
for i in range(N):
# Number of students with score <= sorted_scores[i]
count_less_equal = i + 1
if count_less_equal > threshold:
# Ensure we're counting the unique score only once
# i.e., count only when it's the first occurrence of the score
if i == 0 or sorted_scores[i] != sorted_scores[i - 1]:
count += sorted_scores.count(sorted_scores[i])
return count
def process_test_cases(test_cases):
results = []
for case in test_cases:
N = case[0]
scores = case[1]
results.append(count_boasting_students(N, scores))
return results
# Example usage
def main():
import sys
input = sys.stdin.read
data = input().strip().split('\n')
T = int(data[0])
test_cases = []
index = 1
for _ in range(T):
N = int(data[index])
scores = list(map(int, data[index + 1].split()))
test_cases.append((N, scores))
index += 2
results = process_test_cases(test_cases)
for result in results:
print(result)
if __name__ == "__main__":
main()
Learning course: Design and Analysis of Algorithms
Problem Link: https://www.codechef.com/learn/course/kl-daa/KLDAA2404/problems/AVGFLEXP