Cheap but Similar
Time limit7sMemory limit16 MB
Given a mineral row, decide whether equipment covering 1-3 consecutive cells can be placed to mine at least 75% of the total, and construct a valid placement if so.
- Level
Hard8 of 10
- Topics
- Greedy, Dynamic programming, Simulation
- Solved
- No attempts yet
Problem
Mind the memory limit.
In 2077, a machine called the Sandevistan was developed. It connects to the nervous system and speeds up movement. Mineral X is essential to build it, but Mineral X is extremely expensive. One day, a way to build the same device with much cheaper Mineral Y was discovered, and many companies rushed to mine Mineral Y.
A vein containing Mineral Y is a straight line stretching left to right. The vein consists of cells. The -th cell from the left contains units of mineral. The first cell () has already been developed into a passage and contains no mineral, so .
Mining requires equipment. One piece of equipment can mine all minerals in a consecutive segment of 1 to 3 cells that starts immediately to its right. The equipment must be installed in the cell immediately to the left of the mined segment. For safety reasons, minerals in a cell containing equipment cannot be mined, and equipment cannot be installed on a cell mined by another piece of equipment.
Let the total amount of mineral be . Determine whether it is possible to mine at least minerals. If it is possible, output how to place the equipment and which cells to mine.

This image visualizes the first sample.
Input
The first line contains the number of test cases .
For each test case, the first line contains the length of the vein.
The second line contains , the mineral amounts in the cells, separated by spaces.
The sum of over all test cases does not exceed .
Output
For each test case, if there is no way to mine at least minerals, print NO on the first line.
If there is a way, print YES on the first line. On the second line, print a string of length consisting only of the characters 0, 1, 2, and 3.
If the -th cell is not mined, the -th character must be 0. If the -th cell is mined by equipment whose mined segment has length , the -th character must be .
Hint
This was a hidden problem of SNUPC 2024. Look at the lower-right corner of the contest poster.