1323A. Even Subset Sum Problem - Codeforces Solution C++

  Problem Link : 1323A. Even Subset Sum Problem 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,x;
		cin>>n;
		int pi=-1,pn;
		int ni1=-1,ni2,np1,np2;
		bool flag=0;
		for(int i=1;i<=n;i++)
		{
			cin>>x;
			if(x%2==0)
			{
				flag=1;
				pi=i;
				pn=x;
			//	break;
			}
			else if(ni1==-1)
			{
				ni1=i;
				np1=x;
			}
			else
			{
				flag=1;
				ni2=i;
				np2=x;
			//	break;
			}

		}

		if(flag)
		{
			if(pi!=-1)
				cout<<"1\n"<<pi<<endl;
			else
				cout<<"2\n"<<ni1<<" "<<ni2<<endl;
		}
		else
			cout<<"-1\n";
	}
}

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!