Problem list
Log in
#ioif001 · IOI 2016

Detecting Molecules

Platinum IV 2.0 s 256 MB

You are given the weights $w_1, \dots, w_n$ of $n$ molecules and a target range $[\ell, u]$. Find a non-empty subset of the molecules whose total weight lies in $[\ell, u]$, or report that no such subset exists.

It is guaranteed that $\max_i w_i - \min_i w_i \le u - \ell$.

This is an interactive task. The grader sends you the arguments; you print the subset (or report impossibility). Because many subsets may be valid, the grader validates your subset rather than comparing it to a fixed answer.

Note. This is an adaptation of an IOI function-implementation task to an interactive stdin/stdout problem. The test data is RiseOJ-generated (self-validated against an independent brute force), not the official IOI data.

Interaction / I/O protocol

Input. The grader first sends one line with three integers $n$, $\ell$, $u$. The second line contains $n$ integers $w_1 \dots w_n$.

Output. If a valid subset exists, print its size $m$ ($m \ge 1$) on one line, then $m$ distinct 1-based indices on the next line. If no valid subset exists, print a single line containing -1 (or 0).

Flush after printing. Any valid subset is accepted.

Example. For n=4, [l,u]=[10,12], weights 5 8 7 3:

(receive) 4 10 12
(receive) 5 8 7 3
(send)    2
(send)    1 3

The subset ${1,3}$ has weight $5+7=12 \in [10,12]$, so it is accepted.

Input

The grader first sends one line with three integers $n$, $\ell$, $u$. The second line contains $n$ integers $w_1 \dots w_n$.

Output

If a valid subset exists, print its size $m$ ($m \ge 1$) on one line, then $m$ distinct 1-based indices on the next line. If no valid subset exists, print a single line containing -1 (or 0).

Flush after printing. Any valid subset is accepted.

Constraints

  • $1 \le n \le 200$
  • $1 \le w_i \le 1000$
  • $1 \le \ell \le u \le 20000$
  • $\max_i w_i - \min_i w_i \le u - \ell$
Source
IOI 2016
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code