Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*The input file consists of several blocks of data. Each block starts with the number of candy packets N(1<= N <=10000)
- followed by N integers (each less than 1000)in separate lines,
- giving the number of candies in each packet. After the last block of data there is the number -1. */
- #include<iostream>
- #include <cstdlib>
- #include<string.h>
- using namespace std;
- int main()
- {
- long long count=0,j,i,sum=0,l,temp,t;
- double k;
- cin>>k;
- while(k!=-1&&k<=10000)
- {
- int n=(int)k;
- int a[1005];
- for(i=0;i<n;i++)
- {
- cin>>a[i];
- sum+=a[i];
- }
- temp=sum/n;
- t=n*temp;
- // int temp1=(int)temp;
- // l=sum%n;
- if(t==sum)
- {
- for(j=0;j<n;j++)
- {
- if(a[j]>temp)
- count+=a[j]-temp;
- }
- cout<<count<<endl;
- }
- else
- cout<<-1;
- count=0;
- sum=0;
- cin>>k;
- }
- cin.clear();
- cin.ignore(255,'\n');
- cin.get();
- return 0;
- }
Add Comment
Please, Sign In to add comment