| 3 | #define jaadu ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); |
| 4 | typedef unsigned long long int uli; |
| 5 | int main() |
| 6 | { |
| 7 | jaadu; |
| 8 | int n; |
| 9 | cin>>n; //Input N : No. of candy packets |
| 10 | while(n!= -1){ //Loop until the end of input(denoted by -1) |
| 11 | vector<int>arr(n); |
| 12 | uli sum =0; |
| 13 | for(int i=0;i<n;i++){ |
| 14 | cin>>arr[i]; //Input no. of candies in each packet. |
| 15 | sum += arr[i]; //Count total no. of candies. |
| 16 | } |
| 17 | if(sum%n != 0)cout<<-1<<endl; //If n is not divisible by total candies, then even distribution is not possible. Hence, print -1. |
| 18 | else{ |
| 19 | int res = 0; |
| 20 | int p = sum/n; //No. of candies each should have |
| 21 | for(int i=0;i<n;i++){ |
| 22 | if(p- arr[i] >0 ){ //Calculate no. candies, teacher has to move from bigger packet to smaller. |
| 23 | res += p- arr[i]; |
| 24 | } |
| 25 | } |
| 26 | cout<<res<<endl; //Print result |
| 27 | } |
| 28 | cin>>n; |
| 29 | } |
| 30 | return 0; |
| 31 | } |
nothing calls this directly
no outgoing calls
no test coverage detected