给定一个数组代表的标志学生们。及格分数是学生可以得分的最高分是 ,任务是通过给学生加分来最大化通过考试的学生。
请注意,如果学生获得奖励分数,则所有其他学生也将获得相同数量的奖励分数,但没有任何学生的分数超过 .打印最终能通过考试的学生总数。
例子:
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
方法:让是学生在所有其他人中的最高分,那么可以给予的最大可能的奖励分数将是 .现在,对于每个分数 + (100 – M) ≥ 50 的学生,增加计数。最后打印计数。
下面是上述方法的实现:
C++
// C++ Implementation of above approach.
#include
#include
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= 50)
c += 1;
}
return c;
}
// Driver code
int main()
{
int n = 5;
int marks[] = {0, 21, 83, 45, 64};
cout<
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 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= 50)
c += 1;
}
return c;
}
// Driver code
public static void main(String[] args)
{
int n = 5;
List marks = Arrays.asList(0, 21, 83, 45, 64);
System.out.println(check(n, marks));
}
}
// This code is contributed by mits
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))
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 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= 50)
c += 1;
}
return c;
}
// Driver code
public static void Main()
{
int n = 5;
List marks = new List(new int[]{0, 21, 83, 45, 64});
Console.WriteLine(check(n, marks));
}
}
// This code is contributed by mits
PHP
= 50)
$c += 1;
}
return $c;
}
// Driver code
$n = 5;
$marks = array(0, 21, 83, 45, 64);
echo check($n, $marks);
Javascript
输出:
3