Monday, May 1, 2017

URI Soluiton 1225 Perfect Choir - Solution in C++ | Ad Hoc

URI Soluiton 1225 Perfect Choir - Solution in C++ | Ad Hoc


URI Online Judge Solution  Perfect Choir | Ad Hoc
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1225

Problem Name: URI Problem Perfect Choir
Problem Number : URI - 1225
Online Judge : URI Online Judge Solution
Level: Ad Hoc
Solution Language : C plus plus

URI Solution 1225 Perfect Choir Code in CPP:

#include <stdio.h>

int arr[10001];

int main(int argc, char const *argv[])
{
 int n, s, a, x, i;
 bool b;

 while(scanf("%d", &n) == 1)
 {
  s = 0; b = false;

  for (i = 0; i < n; ++i)
   scanf("%d", &arr[i]);

  for (i = 0; i < n; ++i)
   s += arr[i];

  if(s % n == 0){
   x = s/n;
   a = 1;
   b = true;

   for (i = 0; i < n && arr[i] < x; ++i)
    a += (x - arr[i]);
  }

  if(b) printf("%d\n", a);
  else printf("-1\n");
 }

 return 0;
}

No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.