#K37952. Distribute Apples Efficiently
Distribute Apples Efficiently
Distribute Apples Efficiently
You are given n baskets, where the i-th basket contains a certain number of apples. Your task is to distribute apples among people using a minimal sequence of operations. In each operation, you select exactly one basket and remove one apple from it. You must output exactly n operations, each represented as a binary string of length n, where a '1' at position i means that the i-th basket is selected in that operation and '0' elsewhere.
Note: It is guaranteed that every basket has at least one apple. Hence, each basket can be chosen once. This simple strategy will always yield a valid sequence of operations.
Formally:
Given an integer \( n \) and an array \( baskets = [b_1, b_2, \dots, b_n] \), output n binary strings \( S_1, S_2, \dots, S_n \) such that each \( S_i \) is of length \( n \) and has exactly one character '1' at the \( i^{th} \) position and '0' in all other positions.
inputFormat
The input is given via stdin and consists of two lines:
- The first line contains a single integer \( n \) representing the number of baskets.
- The second line contains \( n \) space-separated integers, where the \( i^{th} \) integer represents the number of apples in the \( i^{th} \) basket.
outputFormat
Output exactly \( n \) lines to stdout. Each line should be a binary string of length \( n \) with exactly one '1', indicating the basket chosen in that operation.
## sample4
3 2 2 2
1000
0100
0010
0001
</p>