NetEase 2016 Research and Development Engineer Programming Scholarship (python)

  • 2021-06-29 11:19:17
  • OfStack

This article shares the programming questions of NetEase 2016 R&D engineers for your reference, the specific contents are as follows

'''
Scholarships
Time limit: 1 second
Space limit: 32768K
Small v has n courses this year, and each has an exam. In order to get a scholarship, small v must have an average score of at least avg.
Each course is composed of normal and exam results, and is fully divided into r.Now he knows that the average time score for each course is ai,
If you want to get one more point in the exam results of this course, younger v will spend bi's time reviewing. If you don't, of course, it will be 0.
At the same time, we can clearly see that no more reviews will lead to more than full scores.In order to get a scholarship, Little v should spend at least some time reviewing.

Enter a description:

The first row contains three integers: n, r, avg (n greater than or equal to 1 is less than or equal to 1e5, r greater than or equal to 1 is less than or equal to 1e9, avg greater than or equal to 1 is less than or equal to 1e6).
Next, the n lines, with two integers each, ai and bi, are less than or equal to 1e6 and greater than or equal to 1

Output description:

1 line to output the answer.

Input example 1:

5 10 9
0 5
9 1
8 1
0 1
9 100

Output example 1:

43

'''

'''
Solving ideas: sorting
Put average score ai and review time bi in ab_firsti, and then ab_i sorted from smallest to largest
Then 1. Find out the total score needed (n*avg) 2, and sum up the average results;If the sum of average results is greater than the total score required, output 0, otherwise:
Access ab_in Sequencei, if ab_If the average score of the current subject in i is already full, visit the next subject. Otherwise, add 1 to the average score of the current subject, 1 to the current total score, and the time consumed plus the review time for which the subject gets 1 point.
The time it takes to output until the current total score equals the target total score.
'''

'''
Code run results:
The answer is correct: Congratulations!The program you submitted passed all the test cases
'''


while True:
 try:
  n, r, avg = [int(each) for each in input().split()]
  ab_i = []
  for i in range(n):
   ab_i.append([int(each) for each in input().split()])
 
  ab_i = sorted(ab_i, key=lambda x: x[1])
 
  target = n * avg
  current = sum([each[0] for each in ab_i])
  time_total = 0
  if current < target:
   index = 0
   while current < target:
    while ab_i[index][0] >= r:
     index += 1
    time_total += ab_i[index][1]
    ab_i[index][0] += 1
    current += 1
   print(time_total)
  else:
   print(0)
 except:
  break

Related articles: