LATEENTR-Editorial

PROBLEM LINK:

Practice
Setter: Charan Narukulla
Tester: Abhilash Movva

DIFFICULTY:

Cake walk

PREREQUISITES:

Math

PROBLEM:

Given a statement, In that
There are N branches in the college. for every N(i)th branch there are M sections. for every M(I)th section students count is given to you. print the minimum number of students who need to be shifted from one section to another section for every branch to make class strength equal.It is guaranteed that student count can be equal in every section(after performing this task).

EXPLANATION:

For each branch calculate the total number of students and find the average.Go through count of each section in the branch , if it is more than average sum it to a variable.the final sum is the answer.

Setter's Solution

int main() {
// your code goes here
int N;
cin>>N;
while(N–){
int M;
cin>>M;
int a[M];
int s=0;
for(int i=0;i<M;i++){
cin>>a[i];
s+=a[i];
}
int c=0;
int avg=(s)/M;
for(int i=0;i<M;i++){
if(a[i]>avg)
c+=(a[i]-avg);
}
std::cout << c << std::endl;
}
return 0;
}

Tester's Solution

#include <bits/stdc++.h>
using namespace std;

int main(){
int N;
cin >> N;
while(N–){
int M; cin >> M;
int a[M], sum=0; for(int i=0; i<M; i++){ cin >> a[i]; sum+=a[i]; }
int avg = sum/M;
int noOfMoves = 0;
for(int i=0; i<M; i++){
if(a[i]<avg){
int temp = a[i];
while(temp<avg){
temp++;
noOfMoves++;
}
}
}
cout << noOfMoves << endl;
}
return 0;
}