Hello coders, today we are going to solve Sereja and Votes CodeChef Solution whose Problem Code is SEAVOTE.

Task
Sereja conducted a voting about N of his opinions. Ai percent of people voted for opinion number i. This statistics is called valid if sum of all Ai is equal to 100.
Now let us define rounding up of a statistics A.
- If Ai is not an integer, it will be rounded up to next integer.
- Otherwise it will be left as it is.
e.g. 4.1 became 5, 4.9 became 5 but 6 will still be 6.
Now let us consider a statistics B of size N in which each of Bi is an integer. Now he wants to know whether there exists some valid statistic A of size N (may contain real numbers) such that after rounding it up, it becomes same as B?
Input Format
- First line of input contain integer T – number of test cases.
- For each test, case first line contains integer N – number of opinions.
- Next line contains N integers B1, B2, …, BN as defined in the problem.
Output Format
For each test case, output YES or NO denoting the answer of the problem, i.e. if there exists some statistics A which could be rounded to make it B, print YES otherwise NO.
Constraints
- 1 ≤ T ≤ 50
- 1 ≤ N ≤ 10000
- 0 ≤ Bi ≤ 1000
Sub tasks
- Subtask #1: N ≤ 100 (50 points)
- Subtask #2: original (50 points)
Example
Sample Input
3
3
30 30 30
4
25 25 25 25
2
50 51
Sample Output
NO
YES
YES
Solution – Sereja and Votes
C++
#include<bits/stdc++.h> using namespace std; int main() { int t, n, s, a, x; scanf("%d",&t); while(t--) { scanf("%d", &n); s = 0; x = 100; for(int i = 0; i < n; i++) { scanf("%d", &a); s += a; if(a) x++; } if(s >= 100 && s < x) printf("YES\n"); else printf("NO\n"); } return 0; }
Python
T = int(input()) for _ in range(T): B = [] N = int(input()) B = list(map(int, input().split())) suma = 0 valid = True count = 0 for i in B: if i > 100: valid = False if i > 0: count += 1 suma = sum(B) if (valid and (suma -100 >=0) and (suma - 100 < count)): print('YES') else: print('NO')
Java
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int t = Integer.parseInt(br.readLine()); while(t-- > 0) { int n = Integer.parseInt(br.readLine()); int count = 0; String[] per = br.readLine().split(" "); int zeros= 0; for(int i=0; i<n; i++) { count += Integer.parseInt(per[i]); if(Integer.parseInt(per[i]) == 0) { zeros++; } } int num = n - zeros; if(count < 100 + num && count >= 100) { sb.append("YES\n"); } else { sb.append("NO\n"); } } System.out.print(sb.toString()); } }
Disclaimer: The above Problem (Sereja and Votes) is generated by CodeChef but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.