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