Scholarship


This is a companion discussion topic for the original entry at https://toph.co/p/scholarship
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