English, asked by sharat1805, 6 months ago

There are N number of baskets so that we want to move apple between baskets so that all baskets have the same number of apples. what is the minimum number of apples that must be moved? It is guaranteed that there exists a way to move apples so as to have an equal number of apples in each baskets write code for this in python fastly plzz help me ​

Answers

Answered by rajathpai2000
10

Answer:

//Moving Apples

// C++

#include<bits/stdc++.h>

using namespace std;

int main(){

   int n;

   cin >> n;

   vector<int> a(n);

   for(auto &i:a){

       cin >> i;

   }

   int avg = accumulate(a.begin(), a.end(), 0)/n;

   int ans = 0;

   for(auto i:a){

       ans += abs(avg - i);

   }

   cout << ans/2;

}

Explanation:

Answered by anurimasingh22
0

Answer:

Relocating Apples

/ C++

#include

using the std namespace;

int primary()

int n;

cin >> n;

a(n); vectorint>;

(auto & i:a)

cin >> I

}

accumulate(a.begin(), a.end(), 0)/n; int avg;

0 for int ans;

i:a for(auto

avg - I = ans += abs;

}

ans/2 cout;

}

To know more about python, click on this link:

https://brainly.in/question/4989805

https://brainly.in/question/9171713

#SPJ3

Similar questions