codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1196B.md (2813B)


      1 Source: https://codeforces.com/problemset/problem/1196/B
      2 
      3 B. Odd Sum Segments
      4 
      5 time limit per test
      6 
      7 3 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You are given an array $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$. You want to split it into exactly $k$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i. e. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $n$ elements of the array $a$ must belong to exactly one of the $k$ subsegments.
     22 
     23 Let's see some examples of dividing the array of length $5$ into $3$ subsegments (not necessarily with odd sums): $[1, 2, 3, 4, 5]$ is the initial array, then all possible ways to divide it into $3$ non-empty non-intersecting subsegments are described below:
     24 
     25 * $[1], [2], [3, 4, 5]$;
     26 * $[1], [2, 3], [4, 5]$;
     27 * $[1], [2, 3, 4], [5]$;
     28 * $[1, 2], [3], [4, 5]$;
     29 * $[1, 2], [3, 4], [5]$;
     30 * $[1, 2, 3], [4], [5]$.
     31 
     32 Of course, it can be impossible to divide the initial array into exactly $k$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.
     33 
     34 You have to answer $q$ independent queries.
     35 
     36 Input
     37 
     38 The first line contains one integer $q$ ($1 \le q \le 2 \cdot 10^5$) — the number of queries. Then $q$ queries follow.
     39 
     40 The first line of the query contains two integers $n$ and $k$ ($1 \le k \le n \le 2 \cdot 10^5$) — the number of elements in the array and the number of subsegments, respectively.
     41 
     42 The second line of the query contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
     43 
     44 It is guaranteed that the sum of $n$ over all queries does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
     45 
     46 Output
     47 
     48 For each query, print the answer to it. If it is impossible to divide the initial array into exactly $k$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $k$ integers $r_1$, $r_2$, ..., $r_k$ such that $1 \le r_1 \lt r_2 \lt \dots \lt r_k = n$, where $r_j$ is the right border of the $j$-th segment (the index of the last element that belongs to the $j$-th segment), so the array is divided into subsegments $[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$. Note that $r_k$ is always $n$ but you should print it anyway.
     49 
     50 Example
     51 
     52 Input
     53 
     54 ```
     55 3
     56 5 3
     57 7 18 3 14 1
     58 5 4
     59 1 2 3 4 5
     60 6 2
     61 1 2 8 4 10 2
     62 ```
     63 
     64 Output
     65 
     66 ```
     67 YES
     68 1 3 5
     69 NO
     70 NO
     71 ```