| 2026 Spring UT CS104c Midterm #2 |
|---|
| Finished |
You have just finished shopping for groceries and now need to bag your items. You've brought two reusable shopping bags and must place each item into one of the two bags. Your apartment is quite a few blocks away from the grocery store, and you'd like to make the trek back as painless as possible by balancing the weight of the items in the two bags to be equal, if possible.
Given the weight of each item (in ounces), determine if there's a way to place each item into one of the two bags so that the total weight of each bag is the same.
The first line of input contains a single integer $$$N$$$ $$$(1 \leq N \leq 100)$$$, the number of grocery items you need to bag.
The next line contains $$$N$$$ space-separate integers $$$w_i$$$ $$$(1 \leq w_i \leq 1000)$$$, the weight of your grocery items (in ounces). It is guaranteed that the total weight of all of your items $$$\sum_{i=1}^N w_i$$$ does not exceed $$$1000$$$ ounces.
Print a string: yes if it is possible to place each item into one of the two bags in a way that the total weight of each bag is the same, and no otherwise.
630 100 70 20 1 21
yes
3100 100 100
no
61 2 4 8 16 31
yes
For the items in Sample Input 1, here is one way to bag the items so that both bags have the same total weight ($$$121$$$ ounces):
First Bag: $$$\{100, 20, 1\}$$$
Second Bag: $$$\{70, 30, 21\}$$$.
| Name |
|---|


