codeforces-scrape

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

1807G1.md (3068B)


      1 Source: https://codeforces.com/problemset/problem/1807/G1
      2 
      3 G1. Subsequence Addition (Easy Version)
      4 
      5 time limit per test
      6 
      7 2 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 The only difference between the two versions is that in this version, the constraints are lower.
     22 
     23 Initially, array $a$ contains just the number $1$. You can perform several operations in order to change the array. In an operation, you can select some subsequence$^{\dagger}$ of $a$ and add into $a$ an element equal to the sum of all elements of the subsequence.
     24 
     25 You are given a final array $c$. Check if $c$ can be obtained from the initial array $a$ by performing some number (possibly 0) of operations on the initial array.
     26 
     27 $^{\dagger}$ A sequence $b$ is a subsequence of a sequence $a$ if $b$ can be obtained from $a$ by the deletion of several (possibly zero, but not all) elements. In other words, select $k$ ($1 \leq k \leq |a|$) distinct indices $i_1, i_2, \dots, i_k$ and insert anywhere into $a$ a new element with the value equal to $a_{i_1} + a_{i_2} + \dots + a_{i_k}$.
     28 
     29 Input
     30 
     31 The first line of the input contains an integer $t$ ($1 \leq t \leq 1000$) — the number of test cases. The description of the test cases follows.
     32 
     33 The first line of each test case contains a single integer $n$ ($1 \leq n \leq 5000$)  — the number of elements the final array $c$ should have.
     34 
     35 The second line of each test case contains $n$ space-separated integers $c_i$ ($1 \leq c_i \leq 5000$)  — the elements of the final array $c$ that should be obtained from the initial array $a$.
     36 
     37 It is guaranteed that the sum of $n$ over all test cases does not exceed $5000$.
     38 
     39 Output
     40 
     41 For each test case, output "YES" (without quotes) if such a sequence of operations exists, and "NO" (without quotes) otherwise.
     42 
     43 You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
     44 
     45 Example
     46 
     47 Input
     48 
     49 ```
     50 6
     51 
     52 1
     53 
     54 1
     55 
     56 1
     57 
     58 2
     59 
     60 5
     61 
     62 5 1 3 2 1
     63 
     64 5
     65 
     66 7 1 5 2 1
     67 
     68 3
     69 
     70 1 1 1
     71 
     72 5
     73 
     74 1 1 4 2 1
     75 ```
     76 
     77 Output
     78 
     79 ```
     80 YES
     81 NO
     82 YES
     83 NO
     84 YES
     85 YES
     86 ```
     87 
     88 Note
     89 
     90 For the first test case, the initial array $a$ is already equal to $[1]$, so the answer is "YES".
     91 
     92 For the second test case, performing any amount of operations will change $a$ to an array of size at least two which doesn't only have the element $2$, thus obtaining the array $[2]$ is impossible and the answer is "NO".
     93 
     94 For the third test case, we can perform the following operations in order to obtain the final given array $c$:
     95 
     96 * Initially, $a = [1]$.
     97 * By choosing the subsequence $[1]$, and inserting $1$ in the array, $a$ changes to $[1, 1]$.
     98 * By choosing the subsequence $[1, 1]$, and inserting $1+1=2$ in the middle of the array, $a$ changes to $[1, 2, 1]$.
     99 * By choosing the subsequence $[1, 2]$, and inserting $1+2=3$ after the first $1$ of the array, $a$ changes to $[1, 3, 2, 1]$.
    100 * By choosing the subsequence $[1, 3, 1]$ and inserting $1+3+1=5$ at the beginning of the array, $a$ changes to $[5, 1, 3, 2, 1]$ (which is the array we needed to obtain).