Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,018 views
in Online Assessments by (150 points)
edited by | 1,018 views

1 Answer

0 like 0 dislike
Best answer

C++ Working Code : 

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
int main() {
    ll n;
    cin>>n;
    ll i = 0 ; 
    ll s = 0 ; vector <ll> b(n+5,0);
    while(i<=n-1){
        cin>>b[i];
        s+=(b[i]);
        i++;
    }
    
    ll mx = 1e18 ; 
    i = 0 ;ll rr = 0 ; 
    long double v = 0 ; 
    while(i<=n-2){
        v = v + b[i];
        long double v55 = abs(s-v);
        
        long double t = i + 1 ; 
        long double t55 = n - i ; 
        
        ll g = floor(v/t);
        ll g55 = floor(v55/t55);
        
        ll d = abs(g55-g);
        if(d<mx){
            mx = d ; 
            rr = i + 1 ; 
        }
        
        i++;
    }
    cout<<rr;
    
    
    
    return 0;
}
by Expert (108,690 points)

Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .