pta L1-088 quietly recommended (python3)

After the ladder competition, the human resources department of a certain company hoped that the organizing committee could recommend a group of outstanding students. Sister Jing Jing was in charge of organizing the recommendation list. The process for companies to accept recommendations is as follows:

  • Only students with a score of 175 or higher will be considered;
  • A total of K batches of recommended lists are accepted;
  • In principle, the scores of students on the same recommendation list should be strictly increased;
  • If some students have the same grades in the ladder competition as the previous one, but they have taken the PAT test and their grades have reached the company's interview score line, it is also acceptable.

Given the scores of all participating students and their PAT test scores, please help Ms. Jing Jing calculate how many students she can recommend to companies at most?

Input format:

Enter 3 positive integers in the first line: N (≤105) is the number of participating students, K (≤5×103) is the recommended batch accepted by the company, and S (≤100) is the PAT interview score line of the company.

Then there are N lines, and each line gives two scores, which are a student's ladder score (maximum score 290) and PAT score (maximum score 100).

Output format:

Output the maximum number of students that Ms. Jingjing can recommend to companies in one line.

Input sample:

10 2 90
203 0
169 91
175 88
175 0
175 90
189 0
189 0
189 95
189 89
256 100

Sample output:

8

Example explanation:

The first batch of students who can choose the four scores of 175, 189, 203, and 256 will have one each. In addition, students with a PAT score of 175 and a PAT score of 90 and students with a PAT score of 189 and 95 can be added to the list. In the second batch, there are only two students with scores of 175 and 189 left to enter the list. In the end, a total of 8 people entered the recommendation list.

python code:

n, k, s = [int(i) for i in input().split()]
t = tuple((input().split() for i in range(n)))
r = 0
d = {}
for a, b in t:
    # 先筛选得分不低于175分和的人
    if int(a) >= 175:
        if int(b) >= s: # 达到面试分数线的人先全部录取
            r += 1
        else:
            # 再按批次录取没有达到面试分数线的人
            if d.get(a,0) < k: 
                r += 1
                d[a] = d.get(a,0) + 1    
print(r)  

 Submit results:

 

Guess you like

Origin blog.csdn.net/weixin_51756038/article/details/130002872