"candy - candy i spoj solution" Code Answer's

You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "candy - candy i spoj solution" answered properly. Developers are finding an appropriate answer about candy - candy i spoj solution related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like candy - candy i spoj solution. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on candy - candy i spoj solution. 

candy - candy i spoj solution

By Distinct DunlinDistinct Dunlin on May 04, 2021
#include <iostream>

#include <cstdio>

using namespace std;


int main(void) {

long long i,j,k,n,sum,a[100001],less,more;

while(1)

{

      scanf("%lld",&n);

//n==-1 indicates the end of the input or values 

      if(n==-1)

      break;

//Initialize less , more and sum with "0" 

      less=0;

      more=0;

      sum=0;

      for(i=1;i<=n;i++)

      {

            scanf("%lld",&a[i]);

      }

      for(i=1;i<=n;i++)

      sum=sum+a[i];

      sum=sum/n;

//sum here indicates number of candies that should be
//there in each packets from here after 

      for(i=1;i<=n;i++)

      {

//calculating more and less as mentioned in our explanation 

            if(a[i]<sum)

            less+=(sum-a[i]);

            else

            more+=(a[i]-sum);

      }

//Incase less and more are not equal then we can't


// keep equal number of candies in all packets

//according to given input otherwise print the output 

      if(less!=more)

      printf("-1\n");

      else

      printf("%lld\n",more);

      

      

}

        return 0;

}




 



Source: www.unleashcodingskills.com

Add Comment

0

All those coders who are working on the Whatever based application and are stuck on candy - candy i spoj solution can get a collection of related answers to their query. Programmers need to enter their query on candy - candy i spoj solution related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about candy - candy i spoj solution for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of candy - candy i spoj solution while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "candy - candy i spoj solution". Visit this developer's friendly online web community, CodeProZone, and get your queries like candy - candy i spoj solution resolved professionally and stay updated to the latest Whatever updates. 

Whatever answers related to "candy - candy i spoj solution"

View All Whatever queries

Whatever queries related to "candy - candy i spoj solution"

Browse Other Code Languages

CodeProZone