# Maximum students to pass after giving bonus to everybody and not exceeding 100 marks

Given an array which represents the marks of students. The passing grade is and maximum marks that a student can score is , the task is to maximize the student that are passing the exam by giving bonus marks to the students.

Note that if a student is given bonus marks then all other students will also be given the same amount of bonus marks without any student’s marks exceeding . Print the total students that can pass the exam in the end.

**Examples:**

Input:arr[] = {0, 21, 83, 45, 64}

Output:3

We can only add maximum of 17 bonus marks to the marks of all the students. So, the final array becomes {17, 38, 100, 62, 81}

Only 3 students will pass the exam.

Input:arr[] = {99, 50, 46, 47, 48, 49, 98}

Output:4

**Approach:** Let be the maximum marks of a student among all others then the maximum possible bonus marks that can be given will be . Now for every student whose **marks + (100 – M) ≥ 50**, increment the count. Print the count in the end.

Below is the implementation of the above approach:

## C++

`// C++ Implementation of above approach. ` `#include<iostream> ` `#include<algorithm> ` `using` `namespace` `std; ` ` ` `// Function to return the number ` `// of students that can pass ` `int` `check(` `int` `n, ` `int` `marks[]) ` `{ ` ` ` `// maximum marks ` ` ` `int` `* x = std::max_element(marks,marks+5); ` ` ` ` ` `// maximum bonus marks that can be given ` ` ` `int` `bonus = 100-(` `int` `)(*x); ` ` ` `int` `c = 0; ` ` ` `for` `(` `int` `i=0; i<n;i++) ` ` ` `{ ` ` ` ` ` `// counting the number of ` ` ` `// students that can pass ` ` ` `if` `(marks[i] + bonus >= 50) ` ` ` `c += 1; ` ` ` `} ` ` ` `return` `c; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` `int` `n = 5; ` `int` `marks[] = {0, 21, 83, 45, 64}; ` `cout<<check(n, marks)<<endl; ` `return` `0; ` `} ` `// This code is contributed by mits ` |

*chevron_right*

*filter_none*

## Java

`// Java Implementation of above approach. ` `import` `java.util.*; ` `class` `GFG{ ` `// Function to return the number ` `// of students that can pass ` `static` `int` `check(` `int` `n, List<Integer> marks) ` `{ ` ` ` `// maximum marks ` ` ` `Integer x = Collections.max(marks); ` ` ` ` ` `// maximum bonus marks that can be given ` ` ` `int` `bonus = ` `100` `-x; ` ` ` `int` `c = ` `0` `; ` ` ` `for` `(` `int` `i=` `0` `; i<n;i++) ` ` ` `{ ` ` ` ` ` `// counting the number of ` ` ` `// students that can pass ` ` ` `if` `(marks.get(i) + bonus >= ` `50` `) ` ` ` `c += ` `1` `; ` ` ` `} ` ` ` `return` `c; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` `int` `n = ` `5` `; ` ` ` `List<Integer> marks = Arrays.asList(` `0` `, ` `21` `, ` `83` `, ` `45` `, ` `64` `); ` `System.out.println(check(n, marks)); ` `} ` `} ` `// This code is contributed by mits ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 Implementation of above approach. ` ` ` `# Function to return the number ` `# of students that can pass ` `def` `check(n, marks): ` ` ` ` ` `# maximum marks ` ` ` `x ` `=` `max` `(marks) ` ` ` ` ` `# maximum bonus marks that can be given ` ` ` `bonus ` `=` `100` `-` `x ` ` ` `c ` `=` `0` ` ` `for` `i ` `in` `range` `(n): ` ` ` ` ` `# counting the number of ` ` ` `# students that can pass ` ` ` `if` `(marks[i] ` `+` `bonus >` `=` `50` `): ` ` ` `c ` `+` `=` `1` ` ` ` ` `return` `c ` ` ` `# Driver code ` `n ` `=` `5` `marks ` `=` `[` `0` `, ` `21` `, ` `83` `, ` `45` `, ` `64` `] ` `print` `(check(n, marks)) ` |

*chevron_right*

*filter_none*

## C#

`// C# Implementation of above approach. ` `using` `System; ` `using` `System.Collections.Generic; ` `using` `System.Collections; ` `using` `System.Linq; ` `class` `GFG{ ` `// Function to return the number ` `// of students that can pass ` `static` `int` `check(` `int` `n, List<` `int` `> marks) ` `{ ` ` ` `// maximum marks ` ` ` `int` `x = marks.Max(); ` ` ` ` ` `// maximum bonus marks that can be given ` ` ` `int` `bonus = 100-x; ` ` ` `int` `c = 0; ` ` ` `for` `(` `int` `i=0; i<n;i++) ` ` ` `{ ` ` ` ` ` `// counting the number of ` ` ` `// students that can pass ` ` ` `if` `(marks[i] + bonus >= 50) ` ` ` `c += 1; ` ` ` `} ` ` ` `return` `c; ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main() ` `{ ` `int` `n = 5; ` `List<` `int` `> marks = ` `new` `List<` `int` `>(` `new` `int` `[]{0, 21, 83, 45, 64}); ` `Console.WriteLine(check(n, marks)); ` `} ` `} ` `// This code is contributed by mits ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` ` ` `// PHP Implementation of above approach. ` ` ` `// Function to return the number ` `// of students that can pass ` `function` `check(` `$n` `, ` `$marks` `) ` `{ ` ` ` `// maximum marks ` ` ` `$x` `= max(` `$marks` `); ` ` ` ` ` `// maximum bonus marks that can be given ` ` ` `$bonus` `= 100-` `$x` `; ` ` ` `$c` `= 0; ` ` ` `for` `(` `$i` `=0; ` `$i` `<` `$n` `;` `$i` `++) ` ` ` `{ ` ` ` ` ` `// counting the number of ` ` ` `// students that can pass ` ` ` `if` `(` `$marks` `[` `$i` `] + ` `$bonus` `>= 50) ` ` ` `$c` `+= 1; ` ` ` `} ` ` ` `return` `$c` `; ` `} ` ` ` `// Driver code ` `$n` `= 5; ` `$marks` `= ` `array` `(0, 21, 83, 45, 64); ` `echo` `check(` `$n` `, ` `$marks` `); ` |

*chevron_right*

*filter_none*

**Output:**

3

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

## Recommended Posts:

- Minimum and maximum number of N chocolates after distribution among K students
- Check if two items can be selected from two different categories without exceeding price
- Find the total marks obtained according to given marking scheme
- Calculate the CGPA and CGPA % of marks obtained by a Student in N subjects
- Program to calculate Percentile of Students
- Distribution of candies according to ages of students
- Why is programming important for first year or school students?
- Number of ways to distribute N Paper Set among M students
- Determine the number of squares of unit area that a given line will pass through.
- Loops and Control Statements (continue, break and pass) in Python
- Count the number of ways to give ranks for N students such that same ranks are possible
- Maximum length Subsequence with alternating sign and maximum Sum
- Maximum element in an array such that its previous and next element product is maximum
- Maximum value of |arr[i] - arr[j]| + |i - j|
- Maximum value of B less than A such that A ^ B = A + B
- Value in a given range with maximum XOR
- Find maximum among x^(y^2) or y^(x^2) where x and y are given
- Maximum value of |arr[0] - arr[1]| + |arr[1] - arr[2]| + ... +|arr[n - 2] - arr[n - 1]| when elements are from 1 to n
- Find maximum value of x such that n! % (k^x) = 0
- Find the maximum value of Y for a given X from given set of lines

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.