-
Notifications
You must be signed in to change notification settings - Fork 0
/
57833173.cpp
96 lines (96 loc) · 2.35 KB
/
57833173.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <bits/stdc++.h>
using namespace std;
int main()
{
int q;
cin>>q;
int n,k;
vector< vector<int> > result;
for(int i=0;i<q;i++)
{
cin>>n>>k;
int sum=0;
bool arr[n];
// is it possible?
int counter=0;
bool searchfor=true;
for(int j=0;j<n;j++)
{
long long s;
cin>>s;
s=s%2;
sum+=s;
if(sum%2==1)
arr[j]=true;
else
arr[j]=false;
if(arr[j]==searchfor)
{
counter++;
searchfor=!searchfor;
}
}
vector<int> node;
if(counter>=k) // possible
{
if(k%2==0) // end with false
{
if(arr[n-1]==true) // impossible
{
result.push_back(node);
continue;
}
searchfor=false;
for(int h=n-1;h>-1 && k>0;h--)
{
if(arr[h]==searchfor)
{
node.push_back(h+1);
searchfor=!searchfor;
k--;
}
}
result.push_back(node);
}
else // end with true
{
if(arr[n-1]==false) // impossible
{
result.push_back(node);
continue;
}
searchfor=true;
for(int h=n-1;h>-1 && k>0;h--)
{
if(arr[h]==searchfor)
{
node.push_back(h+1);
searchfor=!searchfor;
k--;
}
}
result.push_back(node);
}
}
else // impossible
{
result.push_back(node);
}
}
for(int i =0;i<result.size();i++)
{
//cout<<"i = "<<i<<endl;
if(result[i].size()==0)
cout<<"NO"<<endl;
else
{
cout<<"YES"<<endl;
for(int h=result[i].size()-1;h>=0;h--)
{
cout<<result[i][h]<<" ";
}
cout<<endl;
}
}
return 0;
}