PlayStation india

All related to gaming in india

LightBlog

Breaking

Wednesday, 28 December 2022

Pet Store codechef solution in c++ || Starters 71 (Rated for Divs 2, 3 & 4)

 

Problem

Alice and Bob went to a pet store. There are N animals in the store where the i^{th} animal is of type A_i.

Alice decides to buy some of these N animals. Bob decides that he will buy all the animals left in the store after Alice has made the purchase.

Find out whether it is possible that Alice and Bob end up with exactly same multiset of animals.

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of multiple lines of input.
    • The first line of each test case contains an integer N — the number of animals in the store.
    • The next line contains N space separated integers, denoting the type of each animal.

Output Format

For each test case, output on a new line, YES, if it is possible that Alice and Bob end up with exactly same multiset of animals and NO otherwise.

You may print each character in uppercase or lowercase. For example, the strings YESyesYes, and yES are considered identical.

Constraints

  • 1 \leq T \leq 1000
  • 1 \leq N \leq 10^5
  • 1 \leq A_i \leq 100
  • The sum of N over all test cases won't exceed 2\cdot 10^5.

SOLUTION OF THIS QUESTION IN C++
void solve1()
{  
  int n;
  cin >>n;
  vector<int> v(n);
  map<int ,int > m;
  for(int i=0; i<n; ++i)
  {
     cin >> v[i];
     m[v[i]]++;
  }
  int flag = 0;
  for(auto k:m)
  {
   if(k.second%2!=0)
   {
      flag=1;
      break;
   }

  }
  if(flag==1)
  {
   cout<<"NO"<<endl;
  }
  else{
   cout<<"YES"<<endl;
  }

No comments:

Post a Comment