Under construction

Still being built. Things may change

Knapsack Problem

Time limit2sMemory limit1024 MB

Summary
Given item weights and capacity c, decide whether the sets of items with total weight at most c form a matroid, printing a counterexample if not.
Level

Medium5 of 10

Topics
Math, Greedy, Brute force
Solved
No attempts yet

Problem

The knapsack problem is stated as follows. There are nn items, and the ii-th item has weight w_iw\_i and value v_iv\_i. The task is to choose a set of items with maximum total value such that their total weight does not exceed cc, the capacity of the knapsack. The knapsack problem is NP-hard, but it can be solved with dynamic programming in time proportional to the total weight of the items.

However, the knapsack problem can be solved greedily in some cases. One such case is when an instance of the knapsack problem forms a matroid.

A matroid is a pair ⟨X,I⟩\langle X, {\cal I}\rangle, where XX is a finite set and I\cal I is a family of subsets of XX. The elements of I\cal I are called independent. The family I\cal I must satisfy the following axioms.

  1. I≠∅{\cal I} \ne \varnothing;
  2. If A∈IA \in {\cal I} and B⊂AB \subset A, then B∈IB \in {\cal I};
  3. If A,B∈IA, B \in {\cal I} and ∣A∣>∣B∣|A| > |B|, then there exists x∈A∖Bx \in A \setminus B such that B∪{x}∈IB \cup \{x\}\in{\cal I}.

Here ∣A∣|A| is the number of items in the set AA.

An example of a matroid is the set of edges of an undirected graph, where an edge set is independent if it is acyclic.

Let the items have weights w_1,w_2,…,w_nw\_1, w\_2, \ldots, w\_n, and take these items as XX. A set of items {i_1,i_2,…,i_k}\{i\_1, i\_2, \ldots, i\_k\} is called independent if w_i_1+w_i_2+…+w_i_k≤cw\_{i\_1}+w\_{i\_2}+\ldots+w\_{i\_k} \le c. Determine whether this construction forms a matroid for the given w_1,w_2,…,w_nw\_1, w\_2, \ldots, w\_n and cc.

Input

The first line contains an integer nn (1≤n≤501 \le n \le 50). The second line contains nn integers w_1,w_2,…,w_nw\_1, w\_2, \ldots, w\_n (1≤w_i≤1001 \le w\_i \le 100). The third line contains an integer cc (max⁡w_i≤c≤∑w_i\max w\_i \le c \le \sum w\_i).

Output

Print YES if the set of solutions to the knapsack problem forms a matroid. Otherwise, print NO.

In the second case, print on the second line one integer, the number of the axiom that is violated. If axiom 2 or axiom 3 is violated, print on the next two lines the sets AA and BB for which the axiom does not hold. Each set is described by the number of items in it, followed by the numbers of those items.

Examples2

  1. Example 1

    Input
    3
    1 2 3
    4
    
    Expected output
    YES
    
  2. Example 2

    Input
    3
    3 4 5
    7
    
    Expected output
    NO
    3
    2 1 2
    1 3