Scholarship

Your school is going to start a new scholarship program. To apply for this scholarship you have to w…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

a = list(map(int,input().strip().split()))
n=int(input())

le = len(a)
avg = n/le

for i in range(len(a)):
    if a[i]<avg:
        sub = le-1
        n = n - a[i]

result = n/sub
print("%.2f"%result)

what is the problem my code?

#include<iostream>
using namespace std;
int main()
{
    unsigned long int i,j=0,a[100],sum=0,budget;
    while(j<100)
    {
        cin>>a[j];
        sum=sum+a[j];
        j++;
        if(cin.peek()=='\n')
        break;
        
    }
    cin>>budget;
    double avg= (double)budget/(double )j;
    
    for(i=0;i<j;i++)
    {
        if(a[i]<avg)
        {
            j--;
            avg=(double)avg+(double)(avg-a[i])/(double)j;
            a[i]=avg;
            i=-1;
            continue;
        }
    }
    printf("%.2lf\n",avg);
    
    

}

wrong answer on test case 4,
tried multiple methods, all resulting in wrong answe on test case 4

1 Like
inputArr = list(map(int, input().split()))
total = int(input())
avg = total / len(inputArr)
count = 0
for i in inputArr:
    if i < avg:
        total -= i
        count+=1
        avg = total / (len(inputArr)-count)
print('%.2f'%avg)

wrong answer on test case 4,
can anybody tell me, why?

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Scholarship{
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        double sum=0,sum2=0,tk,
         avg,avg2;
        int size,count=0;
        ArrayList<Integer>list=new ArrayList<>();

            while(input.hasNextInt()){
                list.add(input.nextInt());
            }
             tk=list.get(list.size()-1);
             size=list.size()-1;
             avg=tk/size;
           
             Collections.sort(list);   
            for(int i=0;i<list.size();i++){
                if(list.get(i)>avg){
                   break;
                }else{
                    tk=tk-list.get(i);
                    size--;
                }
            }
           avg2=tk/(size);
         System.out.printf("%.2f\n",avg2);
           
        }
     
        
       
        
    
 
}

Why Wrong Ans 4 testcase…

@Md.808136 Try this input:

2 100 50 120 167
400