Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

A Professor conducts a Computer Science paper for **N** students. He had strictly instructed all students to sit according to their roll numbers. However when he started checking the papers, he found out that all the papers were randomly ordered because the students had sat randomly during the exam instead of sitting according to their roll numbers. The order is given in list of integers **roll[ ].** The professor became very angry and he wanted to teach the students a lesson.

He decided to sort the papers according to roll numbers by Bubble Sort and count the number of swaps required for each and every student and deduct as many marks of a student as were the number of swaps required for that student. The marks of every student is given in list of integers **marks[ ] **in the order in which they were sitting. However he also has to maintain the class average greater than or equal to a set minimum **avg**, else he may lose his job. The Professor wants to know whether he should punish the students or save his job.

**Example 1:**

**Input:
**N = 5
avg = 68
roll[] = {3, 2, 4, 1, 5}
marks[] = {50, 67, 89, 79, 58}
**Output: **0
**Explanation: **Overall number of swaps required
is 8. Hence the class average would become
(50 + 67 + 89 + 79 + 58 - 8) / 5 = 67
Since 67 is less than the required minimum (68),
he will not punish the class to save his Job.

**Example 2:**

**Input:**
N = 6
avg = 67.5
roll[] = {5, 4, 1, 3, 2, 6}
marks[] = {78, 98, 86, 67, 78, 79}
**Output: **1
**Explanation: **Overall number of swaps required
is 16. Hence the class average would become
(78 + 98 + 86 + 67 + 78 + 79 - 16) / 6 = 78.33.
Since 78.33 is greater than the required
minimum (67.5), he will punish the class and
deduct the marks.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **shouldPunish() **which takes the array **roll[]** describing the order of students while sitting for the exam, the array **marks[] **describing the marks of the students, an integer **N** denoting the number of students and an **avg **denoting the required minimum average that is to be maintained as input parameters and returns 1 if the professor will punish the students or 0 otherwise.

**Expected Time Complexity: **O(N^{2}).

**Expected Auxiliary Space: **O(1).

**Constraints**:

1 ≤ N ≤ 1000

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Punish the Students

...

Here is some troubleshooting advice:

- Reset the IDE using the second button on the top right corner.
- Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
- Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
- You can access the hints to get an idea about what is expected of you as well as the final solution code.
- You can view the solutions submitted by other users from the submission tab.

Here is some troubleshooting advice for contest problems

- Make sure you are not using ad-blockers.
- Disable browser extensions.
- We recommend using latest version of your browser for best experience.
- Avoid using static/global variables in coding problems as your code is tested against multiple test cases and these tend to retain their previous values.
- Passing the Sample/Custom Test cases in coding problems does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.