1196B - Odd Sum Segments - CodeForces Solution


constructive algorithms math *1200

Please click on ads to support us..

Python Code:

from sys import stdin, stdout
import sys
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_arr(): return list(map(int, sys.stdin.readline().strip().split()))
t = int(input())
while t:
      t-=1
      n,k = get_ints()
            a = get_arr()
      cntodd = 0
      for i in range(0,len(a)):
        if a[i]%2==1:
            cntodd+=1
      if k > cntodd:
        print('NO')
      else:
        if (cntodd - k)%2==1:
            print('NO')
        else:
            print('YES')
            inds = []
            ans = []

            for i in range(0,len(a)):
                if a[i]%2==1:
                    inds.append(int(i))  
                                    for i in range(cntodd-k,len(inds)-1):
              print(inds[i]+1,end=' ')
                        print(n)    







C++ Code:

//! Bismillahi-Rahamanirahim.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define str string
#define vll vector<ll>
#define vs vector<string>
#define vvll(a,n,v) vector<vector<ll>> a(n,vector<ll>(n,v));
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define sp ' '
#define eps 1e-12
#define pi (2*acos(0))
#define sz(n) (int)(n).size()
#define mem(x,y) memset(&x[0],y,sizeof(x))
#define sfor(i,s,n,m) for(ll i=s; i<n; i+=m)
#define refor(i,n,s,m) for(ll i=n-1; i>=s; i-=m)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define torad(x) ((x) * ((2*acos(0))/180.0))
#define todeg(x) ((x) * (180.0/(2*acos(0))))
#define fixangle(x) ((x) > 1 ? 1 : (x) < -1 : (x))
#define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//-------------------------------------------------------------------------//
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>pbd_set;
//-------------------------------------------------------------------------//
//---------------------------main()------------------------------//
int main()
{
    fast();//9
    ll t=1;
    cin >> t;
    while(t--)
    {
        ll n,k,c=0;
        cin >> n >> k;
        vll a(n),b;
        sfor(i,0,n,1)
        {
            cin >> a[i];
            if(a[i]%2!=0)
                {c++;b.pb(i+1);}
        }
        if(c<k)
            cout << "No" << endl;
        else if(c%2==k%2)
        {
            cout << "Yes" << endl;
            sfor(i,0,k-1,1)
            {
                cout << b[i] << sp;
            }
            cout << n << endl;
        }
        else
            cout << "No" << endl;
    }
    return 0;
}
//---------------------------main()------------------------------//
/*

*/


Comments

Submit
0 Comments
More Questions

938A - Word Correction
159C - String Manipulation 10
258A - Little Elephant and Bits
1536C - Diluc and Kaeya
1428C - ABBB
1557A - Ezzat and Two Subsequences
255A - Greg's Workout
1059A - Cashier
1389C - Good String
1561A - Simply Strange Sort
1337B - Kana and Dragon Quest game
137C - History
1443C - The Delivery Dilemma
6C - Alice Bob and Chocolate
1077C - Good Array
285B - Find Marble
6A - Triangle
1729A - Two Elevators
1729B - Decode String
1729C - Jumping on Tiles
1729E - Guess the Cycle Size
553B - Kyoya and Permutation
1729D - Friends and the Restaurant
1606C - Banknotes
580C - Kefa and Park
342A - Xenia and Divisors
1033A - King Escape
39D - Cubical Planet
1453A - Cancel the Trains
645A - Amity Assessment