|
| 1 | +level = "easy" |
| 2 | +name = "loot_merge" |
| 3 | +tags = ["arrays", "sorting", "pirates"] |
| 4 | +time_to_solve_sec = 200 |
| 5 | + |
| 6 | +description_en = """ |
| 7 | +Two pirate crews bring sorted loot lists `port_loot` and `starboard_loot`, where each number is a crate weight in nondecreasing order. |
| 8 | +
|
| 9 | +Merge both loot lists into one summary. Return a sorted array of pairs `[weight, count]`, where `count` is how many crates of that weight appear in total across both crews. |
| 10 | +""" |
| 11 | + |
| 12 | +description_ru = """ |
| 13 | +Две пиратские команды приносят отсортированные списки добычи `port_loot` и `starboard_loot`, где каждое число — это вес ящика, а элементы идут в неубывающем порядке. |
| 14 | +
|
| 15 | +Объедините оба списка добычи в одну сводку. Верните отсортированный массив пар `[weight, count]`, где `count` показывает, сколько ящиков такого веса всего есть у обеих команд. |
| 16 | +""" |
| 17 | + |
| 18 | +limits = """ |
| 19 | +- $0 \\leq \\lvert \\text{port\\_loot} \\rvert,\\ \\lvert \\text{starboard\\_loot} \\rvert \\leq 100$ |
| 20 | +- $0 \\leq \\text{port\\_loot}[i],\\ \\text{starboard\\_loot}[i] \\leq 100$ |
| 21 | +- $\\text{port\\_loot}[i] \\leq \\text{port\\_loot}[i+1]$ |
| 22 | +- $\\text{starboard\\_loot}[i] \\leq \\text{starboard\\_loot}[i+1]$ |
| 23 | +""" |
| 24 | + |
| 25 | +solution = """ |
| 26 | +def solution(port_loot: list[int], starboard_loot: list[int]) -> list[list[int]]: |
| 27 | + c = {} |
| 28 | + for x in port_loot + starboard_loot: |
| 29 | + c[x] = c.get(x, 0) + 1 |
| 30 | + return [[x, c[x]] for x in sorted(c)] |
| 31 | +""" |
| 32 | + |
| 33 | +examples = """ |
| 34 | +solution([], []) == [] |
| 35 | +solution([1], []) == [[1, 1]] |
| 36 | +solution([2, 2], [2]) == [[2, 3]] |
| 37 | +solution([1, 1, 3], [1, 2, 2]) == [[1, 3], [2, 2], [3, 1]] |
| 38 | +""" |
| 39 | + |
| 40 | +[[input_signature]] |
| 41 | +argument_name = "port_loot" |
| 42 | +[input_signature.type] |
| 43 | +name = "array" |
| 44 | +[input_signature.type.nested] |
| 45 | +name = "integer" |
| 46 | + |
| 47 | +[[input_signature]] |
| 48 | +argument_name = "starboard_loot" |
| 49 | +[input_signature.type] |
| 50 | +name = "array" |
| 51 | +[input_signature.type.nested] |
| 52 | +name = "integer" |
| 53 | + |
| 54 | +[output_signature.type] |
| 55 | +name = "array" |
| 56 | +[output_signature.type.nested] |
| 57 | +name = "array" |
| 58 | +[output_signature.type.nested.nested] |
| 59 | +name = "integer" |
| 60 | + |
| 61 | +[[asserts]] |
| 62 | +arguments = [[], []] |
| 63 | +comment = "Both loot lists empty" |
| 64 | +expected = [] |
| 65 | + |
| 66 | +[[asserts]] |
| 67 | +arguments = [[1], []] |
| 68 | +comment = "Only port loot has items" |
| 69 | +expected = [[1, 1]] |
| 70 | + |
| 71 | +[[asserts]] |
| 72 | +arguments = [[], [2]] |
| 73 | +comment = "Only starboard loot has items" |
| 74 | +expected = [[2, 1]] |
| 75 | + |
| 76 | +[[asserts]] |
| 77 | +arguments = [[1], [2]] |
| 78 | +comment = "Two different weights" |
| 79 | +expected = [[1, 1], [2, 1]] |
| 80 | + |
| 81 | +[[asserts]] |
| 82 | +arguments = [[2], [1]] |
| 83 | +comment = "Need sorted summary" |
| 84 | +expected = [[1, 1], [2, 1]] |
| 85 | + |
| 86 | +[[asserts]] |
| 87 | +arguments = [[1, 3], [2]] |
| 88 | +comment = "Three distinct weights" |
| 89 | +expected = [[1, 1], [2, 1], [3, 1]] |
| 90 | + |
| 91 | +[[asserts]] |
| 92 | +arguments = [[1, 2], [3, 4]] |
| 93 | +comment = "All weights unique" |
| 94 | +expected = [[1, 1], [2, 1], [3, 1], [4, 1]] |
| 95 | + |
| 96 | +[[asserts]] |
| 97 | +arguments = [[1, 4, 7], [2, 3, 8]] |
| 98 | +comment = "Alternating weights" |
| 99 | +expected = [[1, 1], [2, 1], [3, 1], [4, 1], [7, 1], [8, 1]] |
| 100 | + |
| 101 | +[[asserts]] |
| 102 | +arguments = [[0, 5], [1, 2, 9]] |
| 103 | +comment = "Different lengths" |
| 104 | +expected = [[0, 1], [1, 1], [2, 1], [5, 1], [9, 1]] |
| 105 | + |
| 106 | +[[asserts]] |
| 107 | +arguments = [[2, 2], [2]] |
| 108 | +comment = "All equal elements" |
| 109 | +expected = [[2, 3]] |
| 110 | + |
| 111 | +[[asserts]] |
| 112 | +arguments = [[1, 1, 3], [1, 2, 2]] |
| 113 | +comment = "Duplicates across both arrays" |
| 114 | +expected = [[1, 3], [2, 2], [3, 1]] |
| 115 | + |
| 116 | +[[asserts]] |
| 117 | +arguments = [[4, 6, 8], [1, 3, 5, 7]] |
| 118 | +comment = "Second list starts smaller" |
| 119 | +expected = [[1, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1]] |
| 120 | + |
| 121 | +[[asserts]] |
| 122 | +arguments = [[0, 0, 0], [0, 0]] |
| 123 | +comment = "Many zeros" |
| 124 | +expected = [[0, 5]] |
| 125 | + |
| 126 | +[[asserts]] |
| 127 | +arguments = [[1, 5, 9], [2, 6]] |
| 128 | +comment = "Shorter second array" |
| 129 | +expected = [[1, 1], [2, 1], [5, 1], [6, 1], [9, 1]] |
| 130 | + |
| 131 | +[[asserts]] |
| 132 | +arguments = [[3], [3, 3, 3]] |
| 133 | +comment = "Equal values and long suffix" |
| 134 | +expected = [[3, 4]] |
| 135 | + |
| 136 | +[[asserts]] |
| 137 | +arguments = [[2, 4, 6, 8], [1, 3, 5, 7, 9]] |
| 138 | +comment = "Fully interleaved values" |
| 139 | +expected = [ |
| 140 | + [ |
| 141 | + 1, |
| 142 | + 1, |
| 143 | + ], |
| 144 | + [ |
| 145 | + 2, |
| 146 | + 1, |
| 147 | + ], |
| 148 | + [ |
| 149 | + 3, |
| 150 | + 1, |
| 151 | + ], |
| 152 | + [ |
| 153 | + 4, |
| 154 | + 1, |
| 155 | + ], |
| 156 | + [ |
| 157 | + 5, |
| 158 | + 1, |
| 159 | + ], |
| 160 | + [ |
| 161 | + 6, |
| 162 | + 1, |
| 163 | + ], |
| 164 | + [ |
| 165 | + 7, |
| 166 | + 1, |
| 167 | + ], |
| 168 | + [ |
| 169 | + 8, |
| 170 | + 1, |
| 171 | + ], |
| 172 | + [ |
| 173 | + 9, |
| 174 | + 1, |
| 175 | + ], |
| 176 | +] |
| 177 | + |
| 178 | +[[asserts]] |
| 179 | +arguments = [[1, 2, 10], [3, 4, 5, 6]] |
| 180 | +comment = "Large tail in first array" |
| 181 | +expected = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [10, 1]] |
| 182 | + |
| 183 | +[[asserts]] |
| 184 | +arguments = [[5, 6, 7], [1, 2, 3, 4]] |
| 185 | +comment = "Second array entirely smaller" |
| 186 | +expected = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1]] |
| 187 | + |
| 188 | +[[asserts]] |
| 189 | +arguments = [[1, 1, 1], [2, 2, 2]] |
| 190 | +comment = "Separated duplicate blocks" |
| 191 | +expected = [[1, 3], [2, 3]] |
| 192 | + |
| 193 | +[[asserts]] |
| 194 | +arguments = [[2, 3, 3, 9], [3, 3, 10]] |
| 195 | +comment = "Many equal middle elements" |
| 196 | +expected = [[2, 1], [3, 4], [9, 1], [10, 1]] |
| 197 | + |
| 198 | +[[asserts]] |
| 199 | +arguments = [[0, 2, 4, 6], [1, 1, 1, 7]] |
| 200 | +comment = "Repeated inserts from second array" |
| 201 | +expected = [[0, 1], [1, 3], [2, 1], [4, 1], [6, 1], [7, 1]] |
| 202 | + |
| 203 | +[[asserts]] |
| 204 | +arguments = [[4, 4, 4], [4, 4]] |
| 205 | +comment = "All same values" |
| 206 | +expected = [[4, 5]] |
| 207 | + |
| 208 | +[[asserts]] |
| 209 | +arguments = [[1, 8], [2, 3, 4, 5, 6, 7]] |
| 210 | +comment = "Long middle section" |
| 211 | +expected = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1]] |
| 212 | + |
| 213 | +[[asserts]] |
| 214 | +arguments = [[2, 5, 8, 11], [1, 4, 7, 10]] |
| 215 | +comment = "Alternating four and four" |
| 216 | +expected = [[1, 1], [2, 1], [4, 1], [5, 1], [7, 1], [8, 1], [10, 1], [11, 1]] |
| 217 | + |
| 218 | +[[asserts]] |
| 219 | +arguments = [[10, 20], [5, 15, 25]] |
| 220 | +comment = "Mixed large numbers" |
| 221 | +expected = [[5, 1], [10, 1], [15, 1], [20, 1], [25, 1]] |
0 commit comments