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.
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?
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.
Input: 3 3 30 30 30 4 25 25 25 25 2 50 51 Output: NO YES YES
#include<iostream> #include<algorithm> #include<string> #include<map> #include<set> #include<cmath> #include<vector> #include<queue> #include<string.h> #include<stdlib.h> #include<cstdio> #define ll long long using namespace std; int main(){ int t; scanf("%d",&t); while(t--){ int n,a; cin>>n; int s1=0,s2=0,s=0; //s1:上界 s2:下界 for(int i=0;i<n;++i){ cin>>a; s1+=a; if(a>0) s2+=a-1; else{ s2+=a; s++; } } if(100>=s2&&100<=s1&&s1<100+n-s) //最后一个条件不要漏掉 cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }