 # EGRANDR - Editorial

Author: Egor Bobyk
Tester: Mugurel Ionut Andreica
Editorialist: Praveen Dhinwa

Cakewalk

### PREREQUISITES:

basic knowledge of programming in any language

### PROBLEM:

You are given grade points of a student in total n courses. Grade points of a student can be between 2 to 5. A grade point of 2 means that student has failed the course.

A student can receive scholarship if he satisfies all of the below given conditions.

• He/She has not failed any course.
• His/Her average grade point is not less than 4.
• There should be at least one course in which he got perfect grade points, (i.e. a grade point of 5).

You have to tell whether the student will be able to receive scholarship or not.

### EXPLANATION:

This is a simple implementation problem. You can check all the conditions easily. See the below given pseudo codes for checking various conditions.

He/She has not failed any course.

failed = false;
for i = 1 to n:
if score[i] == 2:
failed = true;
if (failed) {
willGetScholarship = false;
}


His/Her average grade point is not less than 4.

As we know the average grade point will be sum of all grades divided by n. There are two ways of checking this condition.

Method 1

int totalScore = 0;
for i = 1 to n:
totalScore += score[i]
double averageScore = totalScore / n;
if (averageScore < 4.0) {
willGetScholarship = false;
}


Note that in this method, averageScore is computed in double data type. Whenever possible, you should try to avoid comparison between two doubles due to inability of double representation to store all digits after decimal. You can write the above code in the following way in order to have all of your intermediate calculations in int data type.

int totalScore = 0;
for i = 1 to n:
totalScore += score[i]
if (totaScore < 4 * n) {
willGetScholarship = false;
}


There should be at least one course in which he got perfect grade points, (i.e. a grade point of 5).

gotPerfectScore = false;
for i = 1 to n:
if score[i] == 5:
gotPerfectScore = true;
if (!gotPerfectScore) {
willGetScholarship = false;
}


In this way, you can check all the conditions using a single pass over the array representing the grade points in all the courses. Time complexity of this algorithm will be \mathcal{O}(n) where n denotes number of courses.

### Setter’s and Tester’s Solutions:

I have a doubt. My program gives WA if I sort the grades. Check out my code. If I drop the sort() function, it gives AC otherwise WA. Please check and let me know.

http://ideone.com/Y0MhMu

Well this should not happen. The only problem which is causing this according to me is precision error. Try making GPA as an integer, and keep adding the grade points, and at the end only divide by N.

GPA += A[i];


and then in the if:

GPA >= 4*N && ...


can some one help me in finding why my answer is getting wa
pls check and let me know.

#include <stdio.h>

int main(void) {
int i,t,button,j;
long int n,count=0;
long double avg,sum=0;
scanf("%d",&t);

for(i=0;i<t;i++)
{
scanf("%ld",&n);
int arr[n];

for(j=0,button=0,count=0,sum=0;j<n;j++)
{	scanf("%d",&arr[j]);

if(arr[j]==5)
++count;
if(arr[j]<3)
{
button=1;
break;
}
sum=sum+arr[j];
}
avg=sum/n;
if(count==0||button==1||avg-4.0<0)
printf("No\n");
else
printf("Yes\n");

}

return 0;


}

//