{"problem":{"name":"G. Game of numbers","description":{"content":"— It' s a good game, — Princess said pensively. It was clear that she was thinking about something else. — They like to play various games here in Castles Valley. And they invent ones themselves. Say","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10070G"},"statements":[{"statement_type":"Markdown","content":"— It' s a good game, — Princess said pensively. It was clear that she was thinking about something else.\n\n— They like to play various games here in Castles Valley. And they invent ones themselves. Say, my friend Knight played with a princess a game some time ago, — Dragon thought it was a good idea o tell Princess about another game, if, perhaps, previous game was seemed no interesting for her.\n\nPrincess A. offered Knight to play a game of numbers. She puts down the number zero on a sheet of paper. Let us call this number a _current result_.\n\nFurther steps of princess A. and Knight are described below. She calls any positive integer and Knight says what she must do with this number: to add it to the current result or subtract it from the current result.\n\nPrincess A. performs the action and calculates a new value. This value becomes the new current result.\n\nPrincess A. wants that current result to be not less than zero and not greater than k at any time. The game finishes when an action makes the result out of the range or when a sequence of n numbers, which princess A. conceived, exhausts. \n\nKnight managed to learn the sequence of n numbers that princess A. guessed, and now he wants the game to last as long as possible.\n\nYour task is to compute maximum possible number of actions which Knight is able to perform during the game.\n\nThe first line contains integers n and k (1 ≤ n ≤ 1000,  1 ≤ k ≤ 1000) — the size of sequence which princess A. conceived and an upper bound for a current result which must not be exceeded.\n\nThe second line contains n integers c1, c2, ..., cn (1 ≤ cj ≤ k) — the sequence which princess A. conceived.\n\nIn the first line print integer d — maximum possible number of actions, which Knight is able to perform during the game.\n\nPrint d symbols \"+\" and \"-\" in the second line. Symbol at jth position specifies an action which is applied to jth number in the princess' sequence. If multiple answers exist, choose any of them.\n\n## Input\n\nThe first line contains integers n and k (1 ≤ n ≤ 1000,  1 ≤ k ≤ 1000) — the size of sequence which princess A. conceived and an upper bound for a current result which must not be exceeded.The second line contains n integers c1, c2, ..., cn (1 ≤ cj ≤ k) — the sequence which princess A. conceived.\n\n## Output\n\nIn the first line print integer d — maximum possible number of actions, which Knight is able to perform during the game.Print d symbols \"+\" and \"-\" in the second line. Symbol at jth position specifies an action which is applied to jth number in the princess' sequence. If multiple answers exist, choose any of them.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n, k \\in \\mathbb{Z}^+ $ be given integers.  \nLet $ C = (c_1, c_2, \\dots, c_n) $ be a sequence of positive integers with $ 1 \\leq c_j \\leq k $ for all $ j $.  \nLet $ s_0 = 0 $ be the initial current result.  \nFor each $ j \\in \\{1, \\dots, n\\} $, let $ x_j \\in \\{+1, -1\\} $ denote the choice of operation: add $ c_j $ if $ x_j = +1 $, subtract $ c_j $ if $ x_j = -1 $.  \n\nDefine the partial sum:  \n$$\ns_j = s_{j-1} + x_j \\cdot c_j, \\quad \\text{for } j = 1, \\dots, n.\n$$\n\n**Constraints**  \nFor all $ j \\in \\{0, 1, \\dots, d\\} $, where $ d \\leq n $:  \n$$\n0 \\leq s_j \\leq k.\n$$  \nThe game stops at the first $ j $ such that $ s_j < 0 $ or $ s_j > k $, or when $ j = n $.\n\n**Objective**  \nMaximize $ d \\in \\{0, 1, \\dots, n\\} $ such that there exists a sequence $ (x_1, \\dots, x_d) \\in \\{+1, -1\\}^d $ satisfying:  \n$$\n\\forall j \\in \\{1, \\dots, d\\}, \\quad 0 \\leq s_j \\leq k.\n$$  \nOutput $ d $ and the corresponding sequence of $ d $ symbols (“+” or “-”).","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10070G","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}