We need to parse problem: We have a 100x100 matrix. The cell at row n (0-index? maybe 1-index? Problem says "i-th cell on the n-th row", but typical binomial coefficient indexing: C(n, i) if 0 ≤ i ≤ n, else blocked. So rows are numbered maybe starting from 0? But constraints: 0 ≤ C ≤ 49, 0 ≤ R ≤ 99? Actually constraints: 0 ≤ C ≤ 49, 0 ≤ R ≤ 99? Wait: Input constraints: 0 ≤ C ≤ 49? Actually given: "0 ≤ C ≤ 49"? It says: "0 ≤ C ≤ 49"? Let's check: In problem statement: "0 ≤ C ≤ 49"? The posted constraints: "0 ≤ C ≤ 49"? The sample: R=3, C=2; R=3, C=3; R=5, C=4. So R up to 99? The constraints given: 0 ≤ C ≤ 49? But in example, C=4. Actually the input constraint line: "0 ≤ C ≤ 49"? Let's read: The original problem likely from codechef? Possibly "0 ≤ C ≤ 49"? But sample includes C=4, that's ≤49. And R ≤ 99? They say "0 ≤ R ≤ 99"? Actually they wrote: "0 ≤ C ≤ 490"? That seems weird: "0 ≤ C ≤ 490"? Possibly a typo. Actually the statement: "Constraints 1 ≤ T ≤ 100000 ≤ C ≤ 490 ≤ R ≤ 991 ≤ G ≤ 10^12" That seems messed up. Maybe it's: 1 ≤ T ≤ 1000, 0 ≤ C ≤ 49, 0 ≤ R ≤ 99, 1 ≤ G ≤ 10^12. Usually such problems have R up to 30? But binomial coefficients become huge quickly. However they restrict grid size to 100x100, but binomial coefficients can be huge (C(99,49) ~ 5e28), which is >1e12, so G up to 1e12 is plausible. So we have up to 100 rows, columns up to maybe 99. Actually column index corresponds to i in C(n,i). So columns from 0 to maybe up to 99 (since rows up to 99). But constraints say C ≤ 49? Possibly to keep values manageable? But in sample, C=2,3,4 all ≤49. So maybe C ≤ 49, R ≤ 99. The problem says "0 ≤ C ≤ 49"? Actually the given constraints: "0 ≤ C ≤ 490 ≤ R ≤ 991 ≤ G ≤ 10^12". That seems like mis-formatting. Probably it's: 1 ≤ T ≤ 1000, 0 ≤ C ≤ 49, 0 ≤ R ≤ 99, 1 ≤ G ≤ 10^12. Or maybe 0 ≤ R ≤ 99, 0 ≤ C ≤ 49? However in example, R=3,5. So fine.
We need to output sequence of moves: each move: pick all coins from some unblocked cell in the current column. After move, player moves to column W-1 (where W is current column). So we start at column C, row R? Actually we start at cell (R, C). But the move: On each move, the player must collect all coins from some unblocked cell in the current column. So the first move: current column is C (starting column). The player can choose any cell in column C that is unblocked, i.e., any row n such that 0 ≤ C ≤ n? Actually the cell at (n, C) is unblocked if C ≤ n, and contains C(n, C) coins. So we can pick from any row >= C. Note: The starting row R is given but we are not forced to start by picking from that exact cell? The player starts from the cell situated at row R and column C. But does that mean that initially the player is located at that cell, and maybe he must pick from that cell first? The description: "The player starts from the cell situated at row R and column C in the matrix. The objective is to collect exactly G number of coins from matrix in several moves. There are some rules: On each move the player must collect all the coins from some unblocked cell in the current column. The rules of the game state, that player mustn't be really greedy, so the number of coins he collected must not increase. In other words, if at some move the player collected X coins then further he cannot collect more than X coins in a single move. After each move, the player is immediately moved to some cell of the column W-1 (where W denotes the current column of the player). If the current column of the player has index 0, the game ends. The game ends when player collects exactly G number of coins."
We need to output sequence of moves that win the game. It says "the sequence of moves that win the game". The output: first line contains K, the number of column visited before completion of game. Second line contains K space separated integers, the number of coins collected from the cells, in the order they were collected." It says "number of column visited before completion of game." So K is the number of moves? Actually "number of column visited before completion of game." They say: after each move, player moves to column W-1. So the columns visited: starting column C (but they might not count the starting column as visited? They count moves? The sample: Input: 3 2 5 => Output: 2, then "3 2". So K=2 moves. They collected 3 then 2. Starting at (3,2). They collected 3 from [3,2] (which matches C(3,2)=3). Then they must move to column 1 (since W=2, then W-1=1). Then collect 2 from [2,1] (C(2,1)=2). Total=5. So they made two moves. So K is number of moves. And the sequence of coin amounts. So we need to output the coin amounts collected in each move.
Another note: After each move, the player is immediately moved to some cell of the column W-1. Does the player get to choose which cell to land on? The phrase: "moved to some cell of the column W-1". Probably the player can choose which row in that column he ends up at? Or maybe it's automatic? But the problem doesn't specify any restriction on which row we land on. The move only involves collecting from some cell in current column, and then we are moved to column W-1. Possibly we can land on any row? But the landing row might affect future moves because next move we can pick from any unblocked cell in that column. But we are not forced to pick from the landing row; we can pick any cell in the column. So the landing row doesn't actually matter as long as we can pick any cell in the column. Because the move is "collect all the coins from some unblocked cell in the current column". So regardless of which row we land on, we can choose any cell in that column. So the landing row is irrelevant. The only thing that matters is the column index. So effectively, the game is: we have a starting column C. At each step, we are at a column w (starting w=C). We choose a value x = C(n, w) for some n >= w. Then we add x to total, and must ensure non-increasing sequence: each subsequent x must be <= previous x. Then we move to column w-1. Continue until we decide to stop? Actually the game ends when total exactly equals G. But also if we reach column 0, after a move to column 0? Actually "If the current column of the player has index 0, the game ends." That is after moving to column 0? Actually they say: After each move, the player is immediately moved to some cell of the column W-1 (where W denotes the current column of the player). If the current column of the player has index 0, the game ends. So after a move, we compute new column = old column - 1. If new column = 0, then game ends (presumably we cannot make further moves). But does it end before collecting? Actually we could still collect at column 0? The rule: On each move you collect from current column. So if you are at column 0, you could collect from column 0? But they say if current column is 0, game ends. That might mean that when you reach column 0, you cannot make a move; the game ends. So the last move must be made from a column >=1, after which you move to column 0 and game ends. But what if we achieve G exactly on that move? That's fine. Or we might achieve earlier? The game ends when player collects exactly G number of coins. So if we hit G exactly during a move, we win, regardless of column index? Possibly we stop immediately. The wording: "The game ends when player collects exactly G number of coins." So if we collect exactly G at some move, we are done; we don't need to move further. But they also say "If the current column of the player has index 0, the game ends." So there are two termination conditions: either total coins = G, or column becomes 0. However, we must end exactly at G. So we need to ensure that we hit G before or when column becomes 0, but column becoming 0 doesn't automatically give G. So we need to design moves such that total sum of chosen x_i equals G, and the sequence of x_i is non-increasing, and each x_i is of the form C(n_i, w_i) where w_i is the column index at that move (starting w_1 = C, then w_2 = C-1, ..., w_i = C - (i-1)). So essentially we are selecting a sequence of binomial coefficients: For columns from C down to possibly some column, we choose one binomial coefficient from that column (i.e., choose a row n_i such that n_i >= column index, and take value C(n_i, column_i)). The values must be non-increasing. Also total sum = G. We can choose any rows (independent each time). We can also possibly stop before column reaches 0; after collecting G, game ends even if column >0. So we don't have to use all columns down to 0.
The key is that it's always possible to achieve exactly G given constraints, and we need to output any valid sequence.
Observations: binomial coefficients have many possible values in each column. For a given column j, the possible values are C(j, j)=1, C(j+1, j), C(j+2, j), ... up to maybe C(99, j) but row max is 99? Actually grid is 100x100, so rows 0..99? Possibly rows 0..99 inclusive, so maximum n=99. But they gave G up to 1e12. But binomial coefficients for j up to 49 and n up to 99 can be huge (C(99,49) ~ 5e28) >1e12, so values cover range beyond G. So for each column, there are many possible values.
We need to construct a non-increasing sequence of such values that sums to G. This resembles representing G in a "non-increasing" greedy way using binomial coefficients? Possibly we can always take the largest possible value that does not exceed remaining sum and is ≤ previous value, starting from some initial? But we must also respect column decreasing.
Given that we start at column C, we need to pick first value x1 from column C. Then x2 from column C-1, x3 from column C-2, etc. The sequence length K can be at most C+1 (if we go to column 0), but we can stop earlier.
We need to guarantee existence. Probably we can always construct such a sequence by using representations based on binomial expansions: For any integer G, we can represent it as sum of distinct binomial coefficients (like combinatorial number system). But here we need non-increasing and columns decreasing, and we can repeat values? Yes, we can pick same value multiple times if allowed? But note non-increasing allows equal values. However, can we pick same value from different columns? Possibly yes.
But we also need to ensure that from column j, we can pick any value up to some maximum, but also we can pick many values as long as we have rows. There might be a known solution: For each test case, we can simulate picking the largest possible binomial coefficient ≤ current remaining sum, subject to being ≤ previous pick, and from current column. But does that always work? Need to check.
Alternatively, maybe we can always take x_i = C(R_i, current column) where R_i = current column + something? The starting row R is given but we are not forced to use it. So we have flexibility.
Let's think about known problem: This is similar to "Bico Grid" from CodeChef? Possibly from a contest. I recall a problem where you start at (R,C) and you can move left columns picking binomial coefficients with non-increasing values. The solution often involves representing G in base something or using greedy with largest binomial coefficient less than or equal to remaining and not exceeding previous.
But we must also ensure that the value we pick from column j is actually achievable: For column j, the set of values is {C(n, j) for n from j to 99}. For j fixed, as n increases, C(n, j) increases (strictly for n >= j). So it's strictly increasing sequence as n increases. So we can get any integer that is exactly of that form, but not all integers. So we need to pick values that are binomial coefficients.
Thus we need to choose a sequence of binomial coefficients from specific columns that sum to G.
The guarantee: "It is guaranteed that if the player will play optimally it is possible to win the game." But the input doesn't give any additional info about R? Possibly the starting row R is irrelevant? But note: The player starts at cell (R, C). Does that impose that the first move must be from that exact cell? The description says "The player starts from the cell situated at row R and column C in the matrix." Then "On each move the player must collect all the coins from some unblocked cell in the current column." It doesn't explicitly say that the first move must be from the starting cell. However, the example: For (3,2,5) they picked 3 from [3,2], which is exactly the starting cell. For (3,3,10) they picked 10 from [5,3], not from starting cell (3,3) which would be C(3,3)=1. So first move can be from any cell in column C, not necessarily the starting row. So the starting row is irrelevant? But maybe it's given as part of the game's initial position, but we can choose any cell to collect from. So R is irrelevant for the solution? But the problem includes it; maybe it's just part of the scenario but not used. But the constraints have R up to 99, and we need to output any solution. So we can ignore R? But we must ensure that the cells we pick exist (i.e., row <=99). The grid is 100x100, so rows 0..99 inclusive (or 1..100? The sample uses rows starting from 0 or 1? They wrote [3,2] for R=3,C=2. If rows are 0-indexed, C(3,2)=3. And [2,1] = C(2,1)=2. So they are using 0-index? Row 2 means n=2? C(2,1)=2 indeed. So rows from 0. So maximum row 99.
Thus our picks must have n <=99. Since C ≤49 (maybe up to 49), n can be up to 99, which is enough to get many values. But for column j, the maximum value is C(99, j). For j up to 49, C(99,49) is huge, >1e12, so we can represent up to 1e12 easily. However, for larger j close to 99? But C max is 49? So safe.
Thus we can always pick a value <= remaining G as long as we can find a binomial coefficient ≤ some bound. Since values are increasing with n, we can choose the largest C(n, j) that is ≤ some bound (like previous pick or remaining). But we need to guarantee existence of such representation for any G up to 1e12. We need to construct a sequence that sums to G with non-increasing property.
One idea: Use greedy from leftmost column (largest j) to smallest j. But the sum must be exactly G. Could we represent G as sum of binomial coefficients with decreasing column indices, where each coefficient is at most previous? This looks like we are constructing a representation of G in "combinatorial number system" but with a twist: The combinatorial number system represents any integer uniquely as sum of binomial coefficients C(a_k, k) + C(a_{k-1}, k-1) + ... with a_k > a_{k-1} > ... . In that representation, the binomial coefficients are strictly increasing? Actually the standard representation (also called "combinadic") for a given N, we find the largest k such that C(k, k) <= N? Wait: There's a representation: N = C(a_1,1) + C(a_2,2) + ... + C(a_k, k) with a_1 < a_2 < ... < a_k (or a_1 > a_2 > ...?). Let's recall: The combinatorial number system for representing integers in order of combinations: For a given integer N, its representation as sum of binomial coefficients: N = C(c_1, 1) + C(c_2, 2) + ... + C(c_k, k) where c_1 < c_2 < ... < c_k. This is used to map N to a combination. Also there is representation N = C(b_k, k) + C(b_{k-1}, k-1) + ... + C(b_1,1) with b_k > b_{k-1} > ... > b_1 >=0. That's essentially the same. In that representation, the binomial coefficients are not necessarily non-increasing; they can be increasing because C(b_i, i) could be larger or smaller depending. Actually, if we have decreasing columns (i decreasing), C(b_i, i) might be smaller typically. In combinatorial number system, the binomial coefficients chosen are strictly decreasing? Let's examine: For representing N, we find the largest k such that C(k, k) <= N? Not exactly.
Alternative: There is a known fact: Every positive integer can be uniquely expressed as sum of binomial coefficients with non-increasing "choose" values? Not sure.
But our constraints also require that each chosen value is ≤ previous value. Since column indices are decreasing, generally binomial coefficients C(n, j) for fixed n decreases as j increases? Actually, for fixed n, C(n, j) is largest at j=floor(n/2). So if we go from higher column index to lower, the values could be larger or smaller depending on n. But we can control n.
We need to design an algorithm to output any sequence.
Given that T can be up to maybe 1000? Actually constraints say T up to 100000? That seems high. But maybe T up to 10^5? The line says "1 ≤ T ≤ 100000 ≤ C ≤ 490 ≤ R ≤ 991 ≤ G ≤ 10^12" which is garbled. Possibly T up to 1000 or 10000. But we need efficient solution per test case.
We need to produce a sequence of moves (list of integers). The length K can be at most something like C+1? But output length may be up to 50 maybe.
We need to ensure that we can always construct such a sequence. This is reminiscent of the concept of "non-increasing sequence of binomial coefficients that sums to G" and we can use a greedy approach: Starting from column = C, we pick the largest possible value from that column that is ≤ G and also ≤ previous (but no previous initially). Then subtract from G, move to column-1, and continue, but we must ensure that the remaining G can be achieved with further columns and non-increasing condition. However, if we pick a large value now, the next pick must be ≤ that value, but also from a smaller column. Since column is smaller, the maximum possible value we can get from that column (with n max = 99) might be less than the current pick, so that's okay if we pick a value not too high? Actually, the maximum value from column j-1 can be C(99, j-1) which might be larger than C(99, j) for some j? Compare C(99, j) and C(99, j-1). Ratio: C(99, j) / C(99, j-1) = (100 - j)/j. For j <= 49, (100 - j)/j >= 1 when 100 - j >= j => j <= 50. So for j <= 49, C(99, j) is increasing as j increases from 0 to 49? Actually binomial coefficient for fixed n is symmetric, increasing up to n/2. For n=99, max at j=49 or 50. So C(99, 49) > C(99, 48) > ... So the maximum possible value from a column j is not monotonic with j: For j up to 49, larger j yields larger max. So as we move to smaller j, the max possible value decreases. So if we pick a value from column j that is relatively high (close to C(99,j)), then next column j-1's max might be lower, which is okay for non-increasing because next value must be ≤ current, and max is lower so we can always pick something ≤ current. However, if we pick a low value from column j, next column could pick a value higher? No, non-increasing forbids higher. So we must ensure that subsequent picks are ≤ current pick. So if we pick too low early, we restrict later picks to be even lower, which may make it impossible to reach the sum. So it's safer to pick as large as possible initially? But we also need to exactly sum to G.
Given that we have many columns, we can always adjust by picking 1's at the end since column 0 gives C(n,0)=1 for any n, and column 1 gives values like C(n,1)=n, which can be as low as 1 (if n=1? Actually C(1,1)=1; but column 1 gives values: C(1,1)=1? Wait column index j: C(n, j) requires n>=j. So smallest value for column j is C(j, j)=1. For any column j>=1, the minimum value is 1 (by picking n=j). For column 0, C(n,0)=1 for any n. So the minimal coin per move is 1. So we can always pad with 1's later if needed, as long as non-increasing holds (1's are ≤ previous). So we can always reduce remaining sum to zero using ones, provided that we don't violate non-increasing: we need to ensure that when we start using 1's, the previous value is >=1, which will be true. So the main challenge is to represent G as sum of a non-increasing sequence where each term is a binomial coefficient from a specific column (decreasing column indices). Since we can always append 1's from columns down to 0 to fill any remaining sum, as long as the sequence remains non-increasing. However, we must also ensure that we don't exceed column 0? Actually we can only use columns down to 0. If we need many 1's, we can use column 0 repeatedly? No, each move moves to next column. So columns go C, C-1, C-2, ..., 0. We have at most C+1 moves if we go down to column 0. So we have a limited number of moves, at most C+1. Therefore we cannot use arbitrarily many 1's; we have a limit on the number of terms (moves) = at most C+1. Because after we use column 0, we cannot make more moves (game ends). Actually, if we are at column w, after picking, we move to w-1. If w=0, game ends after move? But if we are at column 0, can we make a move? The rule: "If the current column of the player has index 0, the game ends." I interpret that if at the start of a move, the column is 0, the game ends (or maybe after moving to column 0, the game ends). But typical interpretation: The game ends when column becomes 0. So you cannot make a move from column 0. Therefore, you can only make moves while column >=1. Actually, careful: The game flow: Start at column C. Then you make a move: pick from column C. After that, you are moved to column C-1. Now you are at column C-1. If that column is 0, the game ends. So you cannot make another move from column 0 because the game ends immediately after moving to column 0? The statement: "After each move, the player is immediately moved to some cell of the column W-1 (where W denotes the current column of the player). If the current column of the player has index 0, the game ends." So after moving, we check the new column; if it's 0, game ends. So if we move to column 0, we cannot make a move from column 0. So the last move we can make is when we are at column 1: we pick from column 1, then move to column 0, game ends. So we can make moves for columns: C, C-1, ..., 1. That's C moves at most (if C>=1). Actually if C=0 initially, then start at column 0? Then maybe the game ends immediately? But G≥1, so must collect something, but maybe C≥1? Input constraint C maybe ≥0 but if C=0, then we start at column 0 and maybe can pick from column 0? But statement: "If the current column of the player has index 0, the game ends." So if starting column is 0, game ends immediately before any move, cannot collect. So likely C≥1. In constraints it may be >=1. The sample C=2,3,4. So we assume C≥1.
Thus maximum number of moves is C (since we start at column C, then we can use columns C, C-1, ..., 1). That's exactly C moves. But note we could also stop earlier when total G reached, so we may not use all columns. So we have at most C terms in the sum.
Therefore we need to represent G as sum of at most C numbers, each from respective column's binomial set, with non-increasing order.
Since C ≤ 49 (or maybe up to 99?), but at most 50, that's small.
Now, the existence guarantee: "It is guaranteed that if the player will play optimally it is possible to win the game." Means given starting (R,C,G) (maybe with some constraints on R?), there exists a winning strategy. But R is maybe used as an upper bound for the row we can pick? Actually maybe there is an additional constraint: The player starts at cell (R,C). Does that impose that for the first move, the player must pick from a cell with row ≤ R? Or maybe the player can only pick from cells that are at or above? The problem statement: "On each move the player must collect all the coins from some unblocked cell in the current column." It doesn't restrict row based on starting position. So I think R is irrelevant. But why give R? Possibly to mislead or because it's part of the game story: starting cell is given but you can move to any cell in that column? The sample with R=3, C=3, G=10: they picked from row 5, which is > R. So no restriction. So R is indeed irrelevant. But maybe it's used as an upper bound for the rows we can use? They might have limited the rows to be ≤ R? The problem says: "The game field is a 100x100 matrix, where each cell is either a blocked cell, or a cell with some number of coins. For a regular player the look of the field seems pretty random, but the programmer in you recognizes the following pattern: the i-th cell on the n-th row contains C(n, i) coins if and only if 0 ≤ i ≤ n, all other cells are blocked." It doesn't say anything about rows beyond R. So all rows up to 99 are available.
Thus R is irrelevant. But they might have used R as part of constraints to ensure existence? Possibly the existence guarantee depends on R? Or maybe the player is limited to rows ≤ R? That would make sense: if you start at row R, maybe you can only move to rows with index ≤ R? The movement after each move: "After each move, the player is immediately moved to some cell of the column W-1." It doesn't specify which row; maybe the player can choose any row? But perhaps the row is determined: maybe the player moves to the same row? Or to a row equal to something? The phrase "some cell" suggests it could be any cell. But maybe the player is moved to a cell chosen by the game? Actually, maybe the player can decide which cell to move to? Usually in such puzzles, the player can choose the row as well. But they didn't specify who chooses. However, the problem asks to output just the collected coins, not the rows. So it's not necessary to specify rows.
Given that, I suspect R is irrelevant for solution.
Now, we need to produce a valid sequence. Since C is at most around 49, we can brute-force? But T might be large (maybe up to 10^5), so we need O(C) per test case or O(log G) something.
Idea: Use greedy from column 1 upward? Or use representation of G in "base" something? Since we have columns decreasing, we might think of using the combinatorial number system with decreasing indices. There is known representation: Any integer G can be uniquely expressed as sum of distinct binomial coefficients C(n_i, i) with n_i > n_{i-1} >= i? Actually the combinatorial number system for representing a number as sum of binomial coefficients with strictly increasing upper indices and increasing lower indices? Let's recall: For any integer N, there is a unique representation N = C(a_k, k) + C(a_{k-1}, k-1) + ... + C(a_1, 1) where a_k > a_{k-1} > ... > a_1 ≥ 0. This is used for combinadics. Here the lower indices are decreasing from k to 1, but the values C(a_i, i) are not necessarily non-increasing? They could be either. But the property is that this representation uses distinct binomial coefficients and is like a "binary" representation for combinations. And it uses at most k terms where k is such that C(k, k) <= N? Actually the representation's length is determined by the largest i such that C(i, i) <= N? For example, N=5: representation: 5 = C(5,1)? That would be 5, but then a_1=5? But need a_1≥1? Actually standard: N = C(x_1,1) + C(x_2,2) + ... + C(x_k,k) with x_1 < x_2 < ... < x_k. For N=5, we have 5 = C(5,1) (since C(5,1)=5) and that's it; k=1, x_1=5. For N=6, 6 = C(6,1)? 6, but 6 = C(6,1)=6, works. For N=7, 7 = C(7,1)=7. For N=8, 8 = C(8,1)? 8, works? Actually C(8,1)=8. So that representation is just using ones place? That seems trivial. Actually the standard combinadic for representing numbers from 0 to C(n,k)-1 uses exactly k terms. But here we are not limited to a fixed k. There's another representation: any integer can be expressed as sum of distinct binomial coefficients C(n_i, i) with n_i ≥ i and i decreasing? Not exactly.
Alternatively, think about writing G in binary using binomial coefficients as digits? Might be similar to representing G in "factorial number system".
Let's step back. We have a limited number of moves (columns). We need to choose x_i from column i (starting from C down to 1). Let's denote columns we use: w_1 = C, w_2 = C-1, ..., w_K = C-K+1. We need sum = G and x_1 >= x_2 >= ... >= x_K >= 1 (since non-increasing). Also each x_i must be of the form C(n_i, w_i) with n_i ∈ [w_i, 99].
Since C ≤ 49, w_i are at least 1. For small columns, we have many possible values. For column 1, values are n (1..99). For column 2, values are C(n,2) = n(n-1)/2, which for n up to 99 gives up to 4851. For column 3: up to C(99,3) ~ 156849, etc. So for larger columns, values can be huge.
Since G up to 1e12, we may need to use columns up to maybe 10 or 12 to get large values.
Now, the existence guarantee suggests that we can always find a solution. So there must be a constructive method.
One approach: We can try to greedily take the largest possible value from the current column that is ≤ G and also ≤ previous (if any). For the first move, no previous, so we pick the largest C(n, C) ≤ G. Then we set G' = G - x1. Then move to column C-1. For the second move, we need to pick x2 ≤ x1, from column C-1, and we want to cover G'. We can similarly pick the largest C(n, C-1) ≤ min(G', x1). Continue. If at some step, G' becomes 0, we stop. If we reach column 0 or beyond without finishing, we might fail. But the guarantee might ensure that this greedy works? Let's test on sample:
Case1: R=3, C=2, G=5.
Column 2: largest C(n,2) ≤5: C(3,2)=3, C(4,2)=6 >5, so x1=3. G'=2. Column1: largest C(n,1) ≤ min(2, x1=3): C(2,1)=2 is ok. So x2=2. G'=0. Output [3,2] works.
Case2: R=3, C=3, G=10.
Column3: largest C(n,3) ≤10: C(5,3)=10, C(6,3)=20 >10, so x1=10. G'=0 stop. Output [10]. Works.
Case3: R=5, C=4, G=7.
Column4: largest C(n,4) ≤7: C(4,4)=1, C(5,4)=5, C(6,4)=15 >7, so max is 5. So x1=5. G'=2. Column3: need x2 ≤5, largest C(n,3) ≤ min(2,5): C(3,3)=1, C(4,3)=4 >2, so max is 1. x2=1. G'=1. Column2: need x3 ≤1, largest C(n,2) ≤ min(1,1): C(2,2)=1? Wait C(2,2)=1, C(3,2)=3 >1, so x3=1. G'=0. Output [5,1,1] matches sample.
So greedy works for these examples.
Let's test another scenario: Suppose C=2, G=4. Greedy: column2: max ≤4: C(3,2)=3 (since C(4,2)=6 >4). x1=3, G'=1. Column1: max C(n,1) ≤ min(1,3) => max=1 (C(1,1)=1). Sum=4, works: [3,1]. Is that valid? Yes. Could there be a case where greedy fails? For example, C=2, G=2. Greedy: column2: max ≤2: C(2,2)=1? Actually C(2,2)=1, C(3,2)=3>2, so x1=1, G'=1. Column1: max ≤ min(1,1)=1 -> x2=1. Sum=2. Output [1,1] works. But is there a sequence with fewer moves? Possibly [2] from column2? But column2 cannot have 2 because C(2,2)=1, C(3,2)=3, no 2. So greedy gives correct.
Now consider C=2, G=6. Greedy: column2: max ≤6: C(4,2)=6, x1=6, G'=0. Output [6] works.
C=2, G=7: Greedy: column2 max ≤7: still C(4,2)=6, x1=6, G'=1. Column1: max C(n,1) ≤ min(1,6)=1, x2=1. Sum=7. Output [6,1] works.
C=3, G=9: Greedy: column3 max ≤9: C(5,3)=10 >9, C(4,3)=4, so x1=4? Actually C(4,3)=4, C(5,3)=10, so max is 4. x1=4, G'=5. Column2: need ≤4, max C(n,2) ≤ min(5,4): C(4,2)=6 >4, so check C(3,2)=3, C(2,2)=1; max ≤4 is 3? Actually 3 ≤4, and 3 ≤5, so x2=3. G'=2. Column1: need ≤3, max C(n,1) ≤ min(2,3) => max=2 (C(2,1)=2). G'=0. Output [4,3,2]. Is that non-increasing? 4,3,2 yes. But are these values obtainable? x1=4 from column3: C(4,3)=4. x2=3 from column2: C(3,2)=3. x3=2 from column1: C(2,1)=2. Sum=9. Works.
What about C=3, G=8: Greedy: column3 max ≤8: 4 (since 10>8). x1=4, G'=4. Column2: need ≤4, max C(n,2) ≤4: C(3,2)=3, C(4,2)=6>4, so x2=3, G'=1. Column1: need ≤3, max ≤1: x3=1. Sum=8. Works: 4+3+1=8.
C=3, G=11: Greedy: column3 max ≤11: 10? Actually C(5,3)=10, C(6,3)=20 >11, so x1=10, G'=1. Column2: need ≤10, max ≤1: C(1,2) invalid (since n must be ≥2). Minimum C(2,2)=1, so x2=1. G'=0. Output [10,1]. Works.
C=3, G=12: x1=10, G'=2, column2: need ≤10, max ≤2: C(2,2)=1? Wait column2 values: C(2,2)=1, C(3,2)=3>2, so max=1. So x2=1, G'=1, column1: need ≤1, x3=1, sum=12? 10+1+1=12. Works.
C=3, G=13: x1=10, G'=3, column2: need ≤10, max ≤3: C(3,2)=3, ok x2=3, G'=0. Output [10,3]. Check non-increasing: 10 >=3 ok. Works.
C=3, G=14: x1=10, G'=4, column2: need ≤10, max ≤4: C(3,2)=3 (since 4 not available), x2=3, G'=1, column1: x3=1 => sum 14. Works.
C=3, G=15: x1=10, G'=5, column2: max ≤5? C(3,2)=3, C(4,2)=6>5, so x2=3, G'=2, column1: x3=2? Actually column1 max ≤3? Need ≤ min(2,3) =2, so x3=2 (C(2,1)=2). sum=15. Works.
C=3, G=16: x1=10, G'=6, column2: max ≤6? C(4,2)=6, but must also ≤ x1=10, so x2=6, G'=0 => [10,6] but check: column2 value 6 is C(4,2)=6, which is ≤10 ok. Works.
C=3, G=17: x1=10, G'=7, column2: max ≤7: C(4,2)=6, C(5,2)=10>7, so x2=6, G'=1, column1: x3=1 => sum 17.
Seems greedy works for these.
Consider C=4, G=12. Greedy: column4 max ≤12: C(5,4)=5, C(6,4)=15>12, so x1=5, G'=7. column3: need ≤5, max C(n,3) ≤5: C(3,3)=1, C(4,3)=4, C(5,3)=10>5, so max=4, x2=4, G'=3. column2: need ≤4, max C(n,2) ≤3? Wait min(3,4)=3, so max ≤3: C(3,2)=3, x3=3, G'=0 => [5,4,3]. Sum=12. Works.
But does greedy always work? Let's think about a potential failure: Suppose at some column j, the largest possible value ≤ min(G', prev) is x_j. But after picking it, the remaining G'' may not be representable using remaining columns with the non-increasing constraint (i.e., we may need values ≤ x_j). Since we can always use ones later, the only risk is that the remaining sum is too large to be covered by at most j-1 moves, because each move can contribute at most some maximum. But note the maximum sum we can achieve from columns j-1 down to 1 given a limit of non-increasing (i.e., each ≤ x_j) is: for each subsequent column i, the maximum value we can pick is min(x_j, max_possible_in_column_i). Since x_j might be small, we may be limited. But the greedy picks the largest possible at each step, which minimizes the remaining sum and also leaves as much capacity as possible for the later columns? Actually by taking the largest possible now, we reduce the remaining sum as much as possible, but we also restrict later picks to ≤ that large value. But if x_j is very large, later columns have max values that might be even larger? Actually as column index decreases, max values generally decrease (for columns > 49? But for columns up to 49, max increases with column index; so column C is largest index we start with, it has the largest max. Then as we go down, max decreases. So if we pick x_j close to max at column j, that is likely >= max at lower columns, so the restriction x_j will not be binding because later columns' max are smaller. But if we pick a smaller x_j than max at column j, later columns' max might still be larger, but the restriction forces them to be ≤ x_j, which is smaller than their max. That could limit our ability to cover large remaining sum. However, greedy picks the largest possible x_j, so it's the least restrictive? Actually picking largest possible gives highest x_j, which is less restrictive for later columns (since they can be up to x_j, and if x_j is large, they can use their full max). So greedy seems good.
But could there be a scenario where picking the largest x_j leads to a dead end because the remaining sum cannot be expressed as sum of values from smaller columns each ≤ x_j (and with at most (j-1) terms)? While a slightly smaller x_j could allow a feasible representation? This is analogous to coin change with limited coin denominations and a monotonicity constraint. Since the denominations for each column are specific sets (binomial coefficients), not all integers are representable. However, we can always use 1's from the smallest columns, so as long as remaining sum is ≤ (number of remaining moves) * x_j? But we also have to respect that each value must be a binomial coefficient from its column. The set of values in column i includes all integers from some minimum up to max? Not all integers, but many. For column 1, values are all integers from 1 to 99 (since C(n,1)=n). So any integer ≤99 can be represented by column1. For column 2, values are triangular numbers: n(n-1)/2, which are not all integers, but they cover many. However, we can combine with column1 to fill gaps. Since column1 can represent any integer up to 99, we can always fill any small remainder as long as the remainder is ≤ remaining moves * (max value per move) but more importantly we need to represent exactly.
Given that column1 can produce any integer from 1 to 99, and column2 can produce values up to 4851, etc. So for small columns, we have good coverage.
We need to prove greedy works given constraints. Possibly the intended solution is exactly that: For each column from C down to 1, choose the largest possible binomial coefficient that is ≤ remaining G and ≤ previous chosen (if any). And it will always yield exact sum within C moves. The existence guarantee ensures that G is such that this greedy works. But is it guaranteed for any G up to 1e12? Not necessarily; there might be G where greedy fails but some other sequence works. However, problem statement says: "It is guaranteed that if the player will play optimally it is possible to win the game." That suggests that for the given inputs, there is always a solution. But it doesn't guarantee that greedy will always find one. However, maybe the intended solution uses greedy because it's simple and works for all valid inputs due to some property.
Let's test more thoroughly with random small C and G within some range to see if greedy always finds solution. Write a mental brute-force? We can reason.
Define columns indices from c down to 1. We have to pick values v_i ∈ S_i where S_i = { C(n, i) : n from i to 99 }. We need sum = G and non-increasing. Since C ≤ 49, and rows up to 99, S_i contains many values. Greedy: for i from C down to 1, set v_i = max{ x ∈ S_i : x ≤ min(G, prev) } where prev = ∞ for first. Then subtract G -= v_i, set prev = v_i. Continue. At the end, if G becomes 0 before or at column 1, success. If we exhaust columns without reaching 0, failure.
We need to check if there exists any G for which this fails but some other sequence works.
Let's consider extreme cases: Suppose C=1. Then we have only column1. We need to pick a single value v1 from S_1 = {1..99} such that v1 = G. So we need G ≤ 99. For C=1, the existence guarantee likely ensures G ≤ 99. So for C=1, greedy picks v1 = min(99, G) but must equal G exactly, so only works if G ≤ 99. So if G>99, there is no solution. But constraints might ensure that G is not too large relative to C? Possibly the problem guarantees that a solution exists only for certain (R,C,G) pairs? The statement: "It is guaranteed that if the player will play optimally it is possible to win the game." That implies that for the given test cases, there exists a winning strategy. So the inputs are such that a solution exists. For C=1, G must be ≤99. So greedy works if G ≤99 (since it picks v1 = G if G≤99; if G>99, greedy picks 99, then remaining >0 but no columns left -> fail. But since existence guaranteed, such inputs won't appear). So fine.
Now consider C=2. We have columns 2 and 1. We need to represent G as v2 + v1 with v2 >= v1, v2 ∈ S_2 = {C(n,2)} = {1,3,6,10,15,21,28,36,45,55,66,78,91,105,... up to 4851}. v1 ∈ {1..99}. Greedy: v2 = largest triangular ≤ G. Then v1 = min(G - v2, v2) but also must be ≤99 and exactly G - v2. Since v1 can be any integer up to 99, the only possible failure is if after picking v2, the remainder r = G - v2 is >99 or > v2 (since non-increasing: v1 ≤ v2). Greedy ensures v2 ≤ G, and r = G - v2. Since v2 is max triangular ≤ G, r < next triangular - v2? Not necessarily. For G up to what is feasible? Existence guarantee likely ensures that G can be represented with at most C moves and constraints. Let's analyze: For C=2, we need G = t + u, with t triangular (t = n(n-1)/2), u integer 1..99, and u ≤ t. Is it always possible for any G up to maybe large? Not all G can be represented. For example, G=100. Triangular numbers up to 100: 1,3,6,10,15,21,28,36,45,55,66,78,91,105. Greedy picks t=91, r=9. u=9 ≤91 and ≤99, so works. G=101: t=91, r=10 works. G=102: t=91, r=11 works. G=103: t=91, r=12 works. G=104: t=91, r=13 works. G=105: t=105? Actually 105 is triangular (14*15/2=105). Greedy picks t=105, r=0, works. G=106: t=105, r=1, works. G=107: t=105, r=2 works. G=108: t=105, r=3 works. G=109: t=105, r=4 works. G=110: t=105, r=5 works. G=111: t=105, r=6 works but 6 ≤105. So seems many work. What about G=2? t=1 (since 1≤2, next 3>2), r=1, u=1, works. G=4: t=3, r=1, works. G=5: t=3, r=2, works (u=2). G=7: t=6, r=1 works. G=8: t=6, r=2 works. G=9: t=6, r=3 works. G=11: t=10, r=1 works. G=12: t=10, r=2 works. G=13: t=10, r=3 works. G=14: t=10, r=4 works. G=16: t=15, r=1 works. G=17: t=15, r=2 works. G=18: t=15, r=3 works. G=19: t=15, r=4 works. G=20: t=15, r=5 works. G=22: t=21, r=1 works. etc. It seems always possible? But is there any G that cannot be represented? For G= 1000? Triangular numbers up to 1000: 1,3,6,10,15,21,28,36,45,55,66,78,91,105,120,136,153,171,190,210,231,253,276,300,325,351,378,406,435,465,496,528,561,595,630,666,703,741,780,820,861,903,946,990,