Skip to content

Commit d42bf13

Browse files
committed
Added 1807B - Grab the Candies.cpp
1 parent bbe2d22 commit d42bf13

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

1807B - Grab the Candies.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// ॐ नमः शिवाय
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
// Code Written By: Vikash Patel
6+
// Codeforces Profile: https://codeforces.com/profile/vikashpatel
7+
8+
int main()
9+
{
10+
int t;
11+
cin>>t;
12+
while(t--)
13+
{
14+
int n;
15+
cin>>n;
16+
int a[n];
17+
vector<int> m(n,0);
18+
vector<int> b(n,0);
19+
int e=0,f=0;
20+
for(int i=0;i<n;i++)
21+
{
22+
cin>>a[i];
23+
if(a[i]%2==0)
24+
{
25+
m[e]=a[i];
26+
e++;
27+
}
28+
else
29+
{
30+
b[f]=a[i];
31+
f++;
32+
}
33+
}
34+
sort(m.begin(),m.end(),greater<int>());
35+
sort(b.begin(),b.end());
36+
int mi=0,bi=0;
37+
bool ans = true;
38+
for(int i=0;i<n;i++)
39+
{
40+
mi += m[i];
41+
bi += b[i];
42+
if(mi>bi)
43+
{
44+
continue;
45+
}
46+
else
47+
{
48+
ans = false;
49+
break;
50+
}
51+
}
52+
if(ans)
53+
cout<<"YES"<<endl;
54+
else
55+
cout<<"NO"<<endl;
56+
}
57+
return 0;
58+
}

0 commit comments

Comments
 (0)