Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Professor Arena is planning to reward his algorithm students for surviving the first exam in CS 3 2 5 0 . One idea he has
Professor Arena is planning to reward his algorithm students for surviving the first exam in CS One idea he has is to distribute snack bags eg Lays Potato Chips, Pretzels, Doritos, Cheetos, etc. at the lecture following the exam. Unbeknownst to many, Prof. Arena is a bit underpaid and underfunded. Consequently, he must devise a reward system so that he is using his money wisely. After consulting his collegeage daughter, Mia, for some advice, he arrives at the following gameplan:
All students who took the exam must receive at least one snack bag, even if they performed poorly.
Every student should receive more snack bags than any student to their immediate left or right if they scored higher than that student. Similarly, if a student scored lower than a student to their immediate left or right, they must receive fewer snack bags than their neighbor, who scored higher.
You are provided as input a paired list of exam scores and student names in an array corresponding to the order in which students are seated you can imagine this as one big, long row of students You may further assume that all scores are unique ie no two students received the same score on the exam
Write an efficient algorithm to determine the minimum number of snack bags Prof. Arena must purchase so he can distribute them to his class according to the criteria listed above. Your algorithm should print out each students name and the number of snack bags they will receive in addition to the total number of snack bags Prof. Arena must purchase in advance. Do not use pseudocode
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started