broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(limit_a, evs):
    elig = [e for e in evs if e[1] > 6]
    elig.sort(key=lambda e: (-e[2], e[0]))
    admitted = []
    for e in elig:
        if 6 * (len(admitted) + 1) <= limit_a:
            admitted.append(e)
    alloc = {e[0]: 0 for e in evs}
    remaining = limit_a
    open_ = list(admitted)
    while open_:
        share = remaining // len(open_)
        capped = [e for e in open_ if e[1] <= share]
        if not capped:
            for e in open_:
                alloc[e[0]] = share
            remaining -= share * len(open_)
            break
        for e in capped:
            alloc[e[0]] = e[1]
            remaining -= e[1]
            open_.remove(e)
    for e in admitted:
        if remaining <= 0:
            break
        if alloc[e[0]] < e[1]:
            alloc[e[0]] += 1
            remaining -= 1
    return [[k, alloc[k]] for k in sorted(alloc)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: minimum pilot current eligibility',
   [63,
    [['EV4', 24, 3], ['EV5', 8, 1], ['EV2', 6, 0], ['EV3', 5, 1], ['EV1', 5, 3], ['EV0', 24, 3]]],
   [['EV0', 24], ['EV1', 0], ['EV2', 6], ['EV3', 0], ['EV4', 24], ['EV5', 8]]],
  ['regression: minimum pilot current eligibility (partial repair)',
   [16, [['EV3', 16, 2], ['EV0', 16, 3], ['EV2', 5, 2], ['EV1', 5, 1]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 0], ['EV3', 8]]],
  ['control 1', [32, [['EV0', 32, 3], ['EV1', 24, 3]]], [['EV0', 16], ['EV1', 16]]],
  ['control 2', [24, [['EV0', 16, 2], ['EV1', 32, 2], ['EV2', 32, 0], ['EV3', 8, 1]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: minimum pilot current eligibility',
   [32,
    [['EV2', 32, 1], ['EV4', 32, 0], ['EV3', 6, 2], ['EV1', 32, 2], ['EV5', 24, 1],
     ['EV0', 32, 3]]],
   [['EV0', 7], ['EV1', 7], ['EV2', 6], ['EV3', 6], ['EV4', 0], ['EV5', 6]]],
  ['regression: minimum pilot current eligibility (partial repair)',
   [24, [['EV0', 10, 2], ['EV4', 6, 3], ['EV2', 5, 3], ['EV3', 32, 1], ['EV1', 16, 3]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 0], ['EV3', 6], ['EV4', 6]]],
  ['control 1',
   [30,
    [['EV1', 8, 3], ['EV4', 6, 2], ['EV0', 16, 0], ['EV2', 10, 3], ['EV3', 24, 1], ['EV5', 6, 2]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 6]]],
  ['control 2', [40, [['EV1', 5, 1], ['EV0', 32, 2]]], [['EV0', 32], ['EV1', 0]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: minimum pilot current eligibility',
   [16, [['EV0', 6, 1], ['EV2', 5, 1], ['EV1', 24, 3]]], [['EV0', 6], ['EV1', 10], ['EV2', 0]]],
  ['regression: minimum pilot current eligibility (partial repair)',
   [10, [['EV0', 5, 3], ['EV1', 10, 2]]], [['EV0', 0], ['EV1', 10]]],
  ['control 1', [18, [['EV2', 32, 0], ['EV0', 5, 2], ['EV1', 24, 3]]],
   [['EV0', 0], ['EV1', 9], ['EV2', 9]]],
  ['control 2', [16, [['EV0', 24, 3], ['EV1', 16, 0], ['EV2', 16, 2]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 8]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: minimum pilot current eligibility',
   [18, [['EV2', 6, 0], ['EV1', 24, 1], ['EV3', 24, 0], ['EV0', 32, 2]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 0]]],
  ['regression: minimum pilot current eligibility (partial repair)',
   [48, [['EV2', 8, 2], ['EV0', 32, 3], ['EV1', 5, 3]]], [['EV0', 32], ['EV1', 0], ['EV2', 8]]],
  ['control 1', [16, [['EV1', 16, 2], ['EV0', 32, 3]]], [['EV0', 8], ['EV1', 8]]],
  ['control 2',
   [48,
    [['EV3', 8, 0], ['EV1', 16, 0], ['EV4', 5, 0], ['EV2', 8, 0], ['EV5', 10, 0], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 12], ['EV2', 8], ['EV3', 8], ['EV4', 0], ['EV5', 10]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: minimum pilot current eligibility',
   [40, [['EV1', 24, 3], ['EV0', 6, 0], ['EV2', 32, 1], ['EV3', 32, 3]]],
   [['EV0', 6], ['EV1', 12], ['EV2', 11], ['EV3', 11]]],
  ['regression: minimum pilot current eligibility (partial repair)',
   [40,
    [['EV0', 5, 0], ['EV2', 24, 3], ['EV1', 32, 0], ['EV5', 8, 2], ['EV3', 10, 2], ['EV4', 8, 1]]],
   [['EV0', 0], ['EV1', 8], ['EV2', 8], ['EV3', 8], ['EV4', 8], ['EV5', 8]]],
  ['control 1', [40, [['EV2', 5, 0], ['EV0', 6, 2], ['EV3', 24, 2], ['EV1', 10, 3]]],
   [['EV0', 6], ['EV1', 10], ['EV2', 0], ['EV3', 24]]],
  ['control 2', [10, [['EV0', 10, 0]]], [['EV0', 10]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(limit_a, evs):
    elig = [e for e in evs if e[1] >= 5]
    elig.sort(key=lambda e: (-e[2], e[0]))
    admitted = []
    for e in elig:
        if 6 * (len(admitted) + 1) <= limit_a:
            admitted.append(e)
    alloc = {e[0]: 0 for e in evs}
    remaining = limit_a
    open_ = list(admitted)
    while open_:
        share = remaining // len(open_)
        capped = [e for e in open_ if e[1] <= share]
        if not capped:
            for e in open_:
                alloc[e[0]] = share
            remaining -= share * len(open_)
            break
        for e in capped:
            alloc[e[0]] = e[1]
            remaining -= e[1]
            open_.remove(e)
    for e in admitted:
        if remaining <= 0:
            break
        if alloc[e[0]] < e[1]:
            alloc[e[0]] += 1
            remaining -= 1
    return [[k, alloc[k]] for k in sorted(alloc)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: minimum pilot current eligibility',
   [63,
    [['EV4', 24, 3], ['EV5', 8, 1], ['EV2', 6, 0], ['EV3', 5, 1], ['EV1', 5, 3], ['EV0', 24, 3]]],
   [['EV0', 24], ['EV1', 0], ['EV2', 6], ['EV3', 0], ['EV4', 24], ['EV5', 8]]],
  ['regression: minimum pilot current eligibility (partial repair)',
   [16, [['EV3', 16, 2], ['EV0', 16, 3], ['EV2', 5, 2], ['EV1', 5, 1]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 0], ['EV3', 8]]],
  ['control 1', [32, [['EV0', 32, 3], ['EV1', 24, 3]]], [['EV0', 16], ['EV1', 16]]],
  ['control 2', [24, [['EV0', 16, 2], ['EV1', 32, 2], ['EV2', 32, 0], ['EV3', 8, 1]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: minimum pilot current eligibility',
   [32,
    [['EV2', 32, 1], ['EV4', 32, 0], ['EV3', 6, 2], ['EV1', 32, 2], ['EV5', 24, 1],
     ['EV0', 32, 3]]],
   [['EV0', 7], ['EV1', 7], ['EV2', 6], ['EV3', 6], ['EV4', 0], ['EV5', 6]]],
  ['regression: minimum pilot current eligibility (partial repair)',
   [24, [['EV0', 10, 2], ['EV4', 6, 3], ['EV2', 5, 3], ['EV3', 32, 1], ['EV1', 16, 3]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 0], ['EV3', 6], ['EV4', 6]]],
  ['control 1',
   [30,
    [['EV1', 8, 3], ['EV4', 6, 2], ['EV0', 16, 0], ['EV2', 10, 3], ['EV3', 24, 1], ['EV5', 6, 2]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 6]]],
  ['control 2', [40, [['EV1', 5, 1], ['EV0', 32, 2]]], [['EV0', 32], ['EV1', 0]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: minimum pilot current eligibility',
   [16, [['EV0', 6, 1], ['EV2', 5, 1], ['EV1', 24, 3]]], [['EV0', 6], ['EV1', 10], ['EV2', 0]]],
  ['regression: minimum pilot current eligibility (partial repair)',
   [10, [['EV0', 5, 3], ['EV1', 10, 2]]], [['EV0', 0], ['EV1', 10]]],
  ['control 1', [18, [['EV2', 32, 0], ['EV0', 5, 2], ['EV1', 24, 3]]],
   [['EV0', 0], ['EV1', 9], ['EV2', 9]]],
  ['control 2', [16, [['EV0', 24, 3], ['EV1', 16, 0], ['EV2', 16, 2]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 8]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: minimum pilot current eligibility',
   [18, [['EV2', 6, 0], ['EV1', 24, 1], ['EV3', 24, 0], ['EV0', 32, 2]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 0]]],
  ['regression: minimum pilot current eligibility (partial repair)',
   [48, [['EV2', 8, 2], ['EV0', 32, 3], ['EV1', 5, 3]]], [['EV0', 32], ['EV1', 0], ['EV2', 8]]],
  ['control 1', [16, [['EV1', 16, 2], ['EV0', 32, 3]]], [['EV0', 8], ['EV1', 8]]],
  ['control 2',
   [48,
    [['EV3', 8, 0], ['EV1', 16, 0], ['EV4', 5, 0], ['EV2', 8, 0], ['EV5', 10, 0], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 12], ['EV2', 8], ['EV3', 8], ['EV4', 0], ['EV5', 10]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: minimum pilot current eligibility',
   [40, [['EV1', 24, 3], ['EV0', 6, 0], ['EV2', 32, 1], ['EV3', 32, 3]]],
   [['EV0', 6], ['EV1', 12], ['EV2', 11], ['EV3', 11]]],
  ['regression: minimum pilot current eligibility (partial repair)',
   [40,
    [['EV0', 5, 0], ['EV2', 24, 3], ['EV1', 32, 0], ['EV5', 8, 2], ['EV3', 10, 2], ['EV4', 8, 1]]],
   [['EV0', 0], ['EV1', 8], ['EV2', 8], ['EV3', 8], ['EV4', 8], ['EV5', 8]]],
  ['control 1', [40, [['EV2', 5, 0], ['EV0', 6, 2], ['EV3', 24, 2], ['EV1', 10, 3]]],
   [['EV0', 6], ['EV1', 10], ['EV2', 0], ['EV3', 24]]],
  ['control 2', [10, [['EV0', 10, 0]]], [['EV0', 10]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Vehicles whose onboard charger accepts exactly 6 A are left paused.

evs is a list of [id, max_a, priority]. An EV with max_a < 6 cannot be served. Eligible EVs are ordered by priority descending then id; each is admitted while 6*(admitted+1) <= limit_a. Admitted EVs are water-filled: repeatedly give floor(remaining/open) amps, fixing EVs whose max_a <= share at their max. Leftover amps go one each in admission order to EVs below max. Return [[id, amps]] for every EV sorted by id (0 = paused).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(limit_a, evs):
    elig = [e for e in evs if e[1] >= 6]
    elig.sort(key=lambda e: (-e[2], e[0]))
    admitted = []
    for e in elig:
        if 6 * len(admitted) <= limit_a:
            admitted.append(e)
    alloc = {e[0]: 0 for e in evs}
    remaining = limit_a
    open_ = list(admitted)
    while open_:
        share = remaining // len(open_)
        capped = [e for e in open_ if e[1] <= share]
        if not capped:
            for e in open_:
                alloc[e[0]] = share
            remaining -= share * len(open_)
            break
        for e in capped:
            alloc[e[0]] = e[1]
            remaining -= e[1]
            open_.remove(e)
    for e in admitted:
        if remaining <= 0:
            break
        if alloc[e[0]] < e[1]:
            alloc[e[0]] += 1
            remaining -= 1
    return [[k, alloc[k]] for k in sorted(alloc)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: admission headroom',
   [10, [['EV2', 10, 0], ['EV0', 6, 2], ['EV1', 16, 2], ['EV3', 16, 1]]],
   [['EV0', 6], ['EV1', 0], ['EV2', 0], ['EV3', 0]]],
  ['regression: admission headroom (partial repair)',
   [24, [['EV0', 32, 0], ['EV4', 6, 2], ['EV3', 5, 0], ['EV1', 32, 3], ['EV2', 16, 3]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 0], ['EV4', 6]]],
  ['control 1', [32, [['EV0', 32, 3], ['EV1', 24, 3]]], [['EV0', 16], ['EV1', 16]]],
  ['control 2', [24, [['EV0', 16, 2], ['EV1', 32, 2], ['EV2', 32, 0], ['EV3', 8, 1]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: admission headroom',
   [32,
    [['EV2', 32, 1], ['EV4', 32, 0], ['EV3', 6, 2], ['EV1', 32, 2], ['EV5', 24, 1],
     ['EV0', 32, 3]]],
   [['EV0', 7], ['EV1', 7], ['EV2', 6], ['EV3', 6], ['EV4', 0], ['EV5', 6]]],
  ['regression: admission headroom (partial repair)',
   [24, [['EV0', 10, 2], ['EV4', 6, 3], ['EV2', 5, 3], ['EV3', 32, 1], ['EV1', 16, 3]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 0], ['EV3', 6], ['EV4', 6]]],
  ['control 1',
   [30,
    [['EV1', 8, 3], ['EV4', 6, 2], ['EV0', 16, 0], ['EV2', 10, 3], ['EV3', 24, 1], ['EV5', 6, 2]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 6]]],
  ['control 2', [40, [['EV1', 5, 1], ['EV0', 32, 2]]], [['EV0', 32], ['EV1', 0]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: admission headroom',
   [24,
    [['EV1', 5, 3], ['EV3', 8, 0], ['EV2', 8, 3], ['EV5', 8, 3], ['EV4', 24, 3], ['EV0', 24, 1]]],
   [['EV0', 6], ['EV1', 0], ['EV2', 6], ['EV3', 0], ['EV4', 6], ['EV5', 6]]],
  ['regression: admission headroom (partial repair)',
   [12, [['EV1', 8, 2], ['EV0', 8, 3], ['EV2', 10, 2]]], [['EV0', 6], ['EV1', 6], ['EV2', 0]]],
  ['control 1', [18, [['EV2', 32, 0], ['EV0', 5, 2], ['EV1', 24, 3]]],
   [['EV0', 0], ['EV1', 9], ['EV2', 9]]],
  ['control 2', [16, [['EV0', 24, 3], ['EV1', 16, 0], ['EV2', 16, 2]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 8]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: admission headroom',
   [18, [['EV2', 6, 0], ['EV1', 24, 1], ['EV3', 24, 0], ['EV0', 32, 2]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 0]]],
  ['regression: admission headroom (partial repair)',
   [30,
    [['EV5', 24, 0], ['EV0', 6, 0], ['EV3', 10, 1], ['EV1', 8, 0], ['EV4', 6, 0], ['EV2', 6, 0]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 0]]],
  ['control 1', [16, [['EV1', 16, 2], ['EV0', 32, 3]]], [['EV0', 8], ['EV1', 8]]],
  ['control 2',
   [48,
    [['EV3', 8, 0], ['EV1', 16, 0], ['EV4', 5, 0], ['EV2', 8, 0], ['EV5', 10, 0], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 12], ['EV2', 8], ['EV3', 8], ['EV4', 0], ['EV5', 10]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: admission headroom',
   [24, [['EV4', 24, 2], ['EV0', 16, 3], ['EV2', 8, 2], ['EV3', 6, 2], ['EV1', 6, 2]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 0]]],
  ['regression: admission headroom (partial repair)',
   [24, [['EV0', 32, 1], ['EV4', 16, 3], ['EV1', 32, 0], ['EV3', 5, 0], ['EV2', 10, 2]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 0], ['EV4', 6]]],
  ['control 1', [40, [['EV2', 5, 0], ['EV0', 6, 2], ['EV3', 24, 2], ['EV1', 10, 3]]],
   [['EV0', 6], ['EV1', 10], ['EV2', 0], ['EV3', 24]]],
  ['control 2', [10, [['EV0', 10, 0]]], [['EV0', 10]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(limit_a, evs):
    elig = [e for e in evs if e[1] >= 6]
    elig.sort(key=lambda e: (-e[2], e[0]))
    admitted = []
    for e in elig:
        if 6 * (len(admitted) + 1) < limit_a:
            admitted.append(e)
    alloc = {e[0]: 0 for e in evs}
    remaining = limit_a
    open_ = list(admitted)
    while open_:
        share = remaining // len(open_)
        capped = [e for e in open_ if e[1] <= share]
        if not capped:
            for e in open_:
                alloc[e[0]] = share
            remaining -= share * len(open_)
            break
        for e in capped:
            alloc[e[0]] = e[1]
            remaining -= e[1]
            open_.remove(e)
    for e in admitted:
        if remaining <= 0:
            break
        if alloc[e[0]] < e[1]:
            alloc[e[0]] += 1
            remaining -= 1
    return [[k, alloc[k]] for k in sorted(alloc)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: admission headroom',
   [10, [['EV2', 10, 0], ['EV0', 6, 2], ['EV1', 16, 2], ['EV3', 16, 1]]],
   [['EV0', 6], ['EV1', 0], ['EV2', 0], ['EV3', 0]]],
  ['regression: admission headroom (partial repair)',
   [24, [['EV0', 32, 0], ['EV4', 6, 2], ['EV3', 5, 0], ['EV1', 32, 3], ['EV2', 16, 3]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 0], ['EV4', 6]]],
  ['control 1', [32, [['EV0', 32, 3], ['EV1', 24, 3]]], [['EV0', 16], ['EV1', 16]]],
  ['control 2', [24, [['EV0', 16, 2], ['EV1', 32, 2], ['EV2', 32, 0], ['EV3', 8, 1]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: admission headroom',
   [32,
    [['EV2', 32, 1], ['EV4', 32, 0], ['EV3', 6, 2], ['EV1', 32, 2], ['EV5', 24, 1],
     ['EV0', 32, 3]]],
   [['EV0', 7], ['EV1', 7], ['EV2', 6], ['EV3', 6], ['EV4', 0], ['EV5', 6]]],
  ['regression: admission headroom (partial repair)',
   [24, [['EV0', 10, 2], ['EV4', 6, 3], ['EV2', 5, 3], ['EV3', 32, 1], ['EV1', 16, 3]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 0], ['EV3', 6], ['EV4', 6]]],
  ['control 1',
   [30,
    [['EV1', 8, 3], ['EV4', 6, 2], ['EV0', 16, 0], ['EV2', 10, 3], ['EV3', 24, 1], ['EV5', 6, 2]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 6]]],
  ['control 2', [40, [['EV1', 5, 1], ['EV0', 32, 2]]], [['EV0', 32], ['EV1', 0]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: admission headroom',
   [24,
    [['EV1', 5, 3], ['EV3', 8, 0], ['EV2', 8, 3], ['EV5', 8, 3], ['EV4', 24, 3], ['EV0', 24, 1]]],
   [['EV0', 6], ['EV1', 0], ['EV2', 6], ['EV3', 0], ['EV4', 6], ['EV5', 6]]],
  ['regression: admission headroom (partial repair)',
   [12, [['EV1', 8, 2], ['EV0', 8, 3], ['EV2', 10, 2]]], [['EV0', 6], ['EV1', 6], ['EV2', 0]]],
  ['control 1', [18, [['EV2', 32, 0], ['EV0', 5, 2], ['EV1', 24, 3]]],
   [['EV0', 0], ['EV1', 9], ['EV2', 9]]],
  ['control 2', [16, [['EV0', 24, 3], ['EV1', 16, 0], ['EV2', 16, 2]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 8]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: admission headroom',
   [18, [['EV2', 6, 0], ['EV1', 24, 1], ['EV3', 24, 0], ['EV0', 32, 2]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 0]]],
  ['regression: admission headroom (partial repair)',
   [30,
    [['EV5', 24, 0], ['EV0', 6, 0], ['EV3', 10, 1], ['EV1', 8, 0], ['EV4', 6, 0], ['EV2', 6, 0]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 0]]],
  ['control 1', [16, [['EV1', 16, 2], ['EV0', 32, 3]]], [['EV0', 8], ['EV1', 8]]],
  ['control 2',
   [48,
    [['EV3', 8, 0], ['EV1', 16, 0], ['EV4', 5, 0], ['EV2', 8, 0], ['EV5', 10, 0], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 12], ['EV2', 8], ['EV3', 8], ['EV4', 0], ['EV5', 10]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: admission headroom',
   [24, [['EV4', 24, 2], ['EV0', 16, 3], ['EV2', 8, 2], ['EV3', 6, 2], ['EV1', 6, 2]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 0]]],
  ['regression: admission headroom (partial repair)',
   [24, [['EV0', 32, 1], ['EV4', 16, 3], ['EV1', 32, 0], ['EV3', 5, 0], ['EV2', 10, 2]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 0], ['EV4', 6]]],
  ['control 1', [40, [['EV2', 5, 0], ['EV0', 6, 2], ['EV3', 24, 2], ['EV1', 10, 3]]],
   [['EV0', 6], ['EV1', 10], ['EV2', 0], ['EV3', 24]]],
  ['control 2', [10, [['EV0', 10, 0]]], [['EV0', 10]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
One more EV is admitted than the circuit can hold at the minimum current.

evs is a list of [id, max_a, priority]. An EV with max_a < 6 cannot be served. Eligible EVs are ordered by priority descending then id; each is admitted while 6*(admitted+1) <= limit_a. Admitted EVs are water-filled: repeatedly give floor(remaining/open) amps, fixing EVs whose max_a <= share at their max. Leftover amps go one each in admission order to EVs below max. Return [[id, amps]] for every EV sorted by id (0 = paused).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(limit_a, evs):
    elig = [e for e in evs if e[1] >= 6]
    elig.sort(key=lambda e: (e[2], e[0]))
    admitted = []
    for e in elig:
        if 6 * (len(admitted) + 1) <= limit_a:
            admitted.append(e)
    alloc = {e[0]: 0 for e in evs}
    remaining = limit_a
    open_ = list(admitted)
    while open_:
        share = remaining // len(open_)
        capped = [e for e in open_ if e[1] <= share]
        if not capped:
            for e in open_:
                alloc[e[0]] = share
            remaining -= share * len(open_)
            break
        for e in capped:
            alloc[e[0]] = e[1]
            remaining -= e[1]
            open_.remove(e)
    for e in admitted:
        if remaining <= 0:
            break
        if alloc[e[0]] < e[1]:
            alloc[e[0]] += 1
            remaining -= 1
    return [[k, alloc[k]] for k in sorted(alloc)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: priority ordering',
   [10, [['EV2', 10, 0], ['EV0', 6, 2], ['EV1', 16, 2], ['EV3', 16, 1]]],
   [['EV0', 6], ['EV1', 0], ['EV2', 0], ['EV3', 0]]],
  ['regression: priority ordering (partial repair)',
   [16,
    [['EV5', 8, 0], ['EV2', 8, 3], ['EV4', 6, 1], ['EV3', 6, 1], ['EV1', 5, 1], ['EV0', 10, 0]]],
   [['EV0', 0], ['EV1', 0], ['EV2', 8], ['EV3', 6], ['EV4', 0], ['EV5', 0]]],
  ['control 1', [32, [['EV0', 32, 3], ['EV1', 24, 3]]], [['EV0', 16], ['EV1', 16]]],
  ['control 2', [24, [['EV0', 16, 2], ['EV1', 32, 2], ['EV2', 32, 0], ['EV3', 8, 1]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: priority ordering',
   [32,
    [['EV2', 32, 1], ['EV4', 32, 0], ['EV3', 6, 2], ['EV1', 32, 2], ['EV5', 24, 1],
     ['EV0', 32, 3]]],
   [['EV0', 7], ['EV1', 7], ['EV2', 6], ['EV3', 6], ['EV4', 0], ['EV5', 6]]],
  ['regression: priority ordering (partial repair)',
   [16, [['EV2', 8, 2], ['EV1', 32, 2], ['EV0', 6, 3]]], [['EV0', 6], ['EV1', 10], ['EV2', 0]]],
  ['control 1',
   [30,
    [['EV1', 8, 3], ['EV4', 6, 2], ['EV0', 16, 0], ['EV2', 10, 3], ['EV3', 24, 1], ['EV5', 6, 2]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 6]]],
  ['control 2', [40, [['EV1', 5, 1], ['EV0', 32, 2]]], [['EV0', 32], ['EV1', 0]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: priority ordering',
   [48, [['EV1', 16, 2], ['EV0', 16, 2], ['EV4', 32, 3], ['EV2', 24, 3], ['EV3', 24, 3]]],
   [['EV0', 9], ['EV1', 9], ['EV2', 10], ['EV3', 10], ['EV4', 10]]],
  ['regression: priority ordering (partial repair)',
   [12, [['EV0', 16, 0], ['EV2', 16, 0], ['EV1', 32, 0]]], [['EV0', 6], ['EV1', 6], ['EV2', 0]]],
  ['control 1', [18, [['EV2', 32, 0], ['EV0', 5, 2], ['EV1', 24, 3]]],
   [['EV0', 0], ['EV1', 9], ['EV2', 9]]],
  ['control 2', [16, [['EV0', 24, 3], ['EV1', 16, 0], ['EV2', 16, 2]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 8]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: priority ordering',
   [18, [['EV2', 6, 0], ['EV1', 24, 1], ['EV3', 24, 0], ['EV0', 32, 2]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 0]]],
  ['regression: priority ordering (partial repair)',
   [30,
    [['EV5', 24, 0], ['EV0', 6, 0], ['EV3', 10, 1], ['EV1', 8, 0], ['EV4', 6, 0], ['EV2', 6, 0]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 0]]],
  ['control 1', [16, [['EV1', 16, 2], ['EV0', 32, 3]]], [['EV0', 8], ['EV1', 8]]],
  ['control 2',
   [48,
    [['EV3', 8, 0], ['EV1', 16, 0], ['EV4', 5, 0], ['EV2', 8, 0], ['EV5', 10, 0], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 12], ['EV2', 8], ['EV3', 8], ['EV4', 0], ['EV5', 10]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: priority ordering',
   [40, [['EV1', 24, 3], ['EV0', 6, 0], ['EV2', 32, 1], ['EV3', 32, 3]]],
   [['EV0', 6], ['EV1', 12], ['EV2', 11], ['EV3', 11]]],
  ['regression: priority ordering (partial repair)',
   [24, [['EV4', 24, 2], ['EV0', 16, 3], ['EV2', 8, 2], ['EV3', 6, 2], ['EV1', 6, 2]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 0]]],
  ['control 1', [40, [['EV2', 5, 0], ['EV0', 6, 2], ['EV3', 24, 2], ['EV1', 10, 3]]],
   [['EV0', 6], ['EV1', 10], ['EV2', 0], ['EV3', 24]]],
  ['control 2', [10, [['EV0', 10, 0]]], [['EV0', 10]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(limit_a, evs):
    elig = [e for e in evs if e[1] >= 6]
    elig.sort(key=lambda e: (-e[2], -len(e[0])))
    admitted = []
    for e in elig:
        if 6 * (len(admitted) + 1) <= limit_a:
            admitted.append(e)
    alloc = {e[0]: 0 for e in evs}
    remaining = limit_a
    open_ = list(admitted)
    while open_:
        share = remaining // len(open_)
        capped = [e for e in open_ if e[1] <= share]
        if not capped:
            for e in open_:
                alloc[e[0]] = share
            remaining -= share * len(open_)
            break
        for e in capped:
            alloc[e[0]] = e[1]
            remaining -= e[1]
            open_.remove(e)
    for e in admitted:
        if remaining <= 0:
            break
        if alloc[e[0]] < e[1]:
            alloc[e[0]] += 1
            remaining -= 1
    return [[k, alloc[k]] for k in sorted(alloc)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: priority ordering',
   [10, [['EV2', 10, 0], ['EV0', 6, 2], ['EV1', 16, 2], ['EV3', 16, 1]]],
   [['EV0', 6], ['EV1', 0], ['EV2', 0], ['EV3', 0]]],
  ['regression: priority ordering (partial repair)',
   [16,
    [['EV5', 8, 0], ['EV2', 8, 3], ['EV4', 6, 1], ['EV3', 6, 1], ['EV1', 5, 1], ['EV0', 10, 0]]],
   [['EV0', 0], ['EV1', 0], ['EV2', 8], ['EV3', 6], ['EV4', 0], ['EV5', 0]]],
  ['control 1', [32, [['EV0', 32, 3], ['EV1', 24, 3]]], [['EV0', 16], ['EV1', 16]]],
  ['control 2', [24, [['EV0', 16, 2], ['EV1', 32, 2], ['EV2', 32, 0], ['EV3', 8, 1]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: priority ordering',
   [32,
    [['EV2', 32, 1], ['EV4', 32, 0], ['EV3', 6, 2], ['EV1', 32, 2], ['EV5', 24, 1],
     ['EV0', 32, 3]]],
   [['EV0', 7], ['EV1', 7], ['EV2', 6], ['EV3', 6], ['EV4', 0], ['EV5', 6]]],
  ['regression: priority ordering (partial repair)',
   [16, [['EV2', 8, 2], ['EV1', 32, 2], ['EV0', 6, 3]]], [['EV0', 6], ['EV1', 10], ['EV2', 0]]],
  ['control 1',
   [30,
    [['EV1', 8, 3], ['EV4', 6, 2], ['EV0', 16, 0], ['EV2', 10, 3], ['EV3', 24, 1], ['EV5', 6, 2]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 6]]],
  ['control 2', [40, [['EV1', 5, 1], ['EV0', 32, 2]]], [['EV0', 32], ['EV1', 0]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: priority ordering',
   [48, [['EV1', 16, 2], ['EV0', 16, 2], ['EV4', 32, 3], ['EV2', 24, 3], ['EV3', 24, 3]]],
   [['EV0', 9], ['EV1', 9], ['EV2', 10], ['EV3', 10], ['EV4', 10]]],
  ['regression: priority ordering (partial repair)',
   [12, [['EV0', 16, 0], ['EV2', 16, 0], ['EV1', 32, 0]]], [['EV0', 6], ['EV1', 6], ['EV2', 0]]],
  ['control 1', [18, [['EV2', 32, 0], ['EV0', 5, 2], ['EV1', 24, 3]]],
   [['EV0', 0], ['EV1', 9], ['EV2', 9]]],
  ['control 2', [16, [['EV0', 24, 3], ['EV1', 16, 0], ['EV2', 16, 2]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 8]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: priority ordering',
   [18, [['EV2', 6, 0], ['EV1', 24, 1], ['EV3', 24, 0], ['EV0', 32, 2]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 0]]],
  ['regression: priority ordering (partial repair)',
   [30,
    [['EV5', 24, 0], ['EV0', 6, 0], ['EV3', 10, 1], ['EV1', 8, 0], ['EV4', 6, 0], ['EV2', 6, 0]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 0]]],
  ['control 1', [16, [['EV1', 16, 2], ['EV0', 32, 3]]], [['EV0', 8], ['EV1', 8]]],
  ['control 2',
   [48,
    [['EV3', 8, 0], ['EV1', 16, 0], ['EV4', 5, 0], ['EV2', 8, 0], ['EV5', 10, 0], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 12], ['EV2', 8], ['EV3', 8], ['EV4', 0], ['EV5', 10]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: priority ordering',
   [40, [['EV1', 24, 3], ['EV0', 6, 0], ['EV2', 32, 1], ['EV3', 32, 3]]],
   [['EV0', 6], ['EV1', 12], ['EV2', 11], ['EV3', 11]]],
  ['regression: priority ordering (partial repair)',
   [24, [['EV4', 24, 2], ['EV0', 16, 3], ['EV2', 8, 2], ['EV3', 6, 2], ['EV1', 6, 2]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 0]]],
  ['control 1', [40, [['EV2', 5, 0], ['EV0', 6, 2], ['EV3', 24, 2], ['EV1', 10, 3]]],
   [['EV0', 6], ['EV1', 10], ['EV2', 0], ['EV3', 24]]],
  ['control 2', [10, [['EV0', 10, 0]]], [['EV0', 10]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Low-priority vehicles charge while high-priority vehicles are paused.

evs is a list of [id, max_a, priority]. An EV with max_a < 6 cannot be served. Eligible EVs are ordered by priority descending then id; each is admitted while 6*(admitted+1) <= limit_a. Admitted EVs are water-filled: repeatedly give floor(remaining/open) amps, fixing EVs whose max_a <= share at their max. Leftover amps go one each in admission order to EVs below max. Return [[id, amps]] for every EV sorted by id (0 = paused).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(limit_a, evs):
    elig = [e for e in evs if e[1] >= 6]
    elig.sort(key=lambda e: (-e[2], e[0]))
    admitted = []
    for e in elig:
        if 6 * (len(admitted) + 1) <= limit_a:
            admitted.append(e)
    alloc = {e[0]: 0 for e in evs}
    remaining = limit_a
    open_ = list(admitted)
    while open_:
        share = remaining // len(open_)
        capped = [e for e in open_ if e[1] <= share]
        if not capped:
            for e in open_:
                alloc[e[0]] = share
            remaining -= share * len(open_)
            break
        for e in capped:
            alloc[e[0]] = e[1]
            remaining -= share
            open_.remove(e)
    for e in admitted:
        if remaining <= 0:
            break
        if alloc[e[0]] < e[1]:
            alloc[e[0]] += 1
            remaining -= 1
    return [[k, alloc[k]] for k in sorted(alloc)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: capped vehicle surplus return',
   [63,
    [['EV4', 24, 3], ['EV5', 8, 1], ['EV2', 6, 0], ['EV3', 5, 1], ['EV1', 5, 3], ['EV0', 24, 3]]],
   [['EV0', 24], ['EV1', 0], ['EV2', 6], ['EV3', 0], ['EV4', 24], ['EV5', 8]]],
  ['regression: capped vehicle surplus return (partial repair)',
   [30, [['EV0', 8, 0], ['EV1', 16, 3], ['EV2', 32, 0]]], [['EV0', 8], ['EV1', 11], ['EV2', 11]]],
  ['control 1', [32, [['EV0', 32, 3], ['EV1', 24, 3]]], [['EV0', 16], ['EV1', 16]]],
  ['control 2', [24, [['EV0', 16, 2], ['EV1', 32, 2], ['EV2', 32, 0], ['EV3', 8, 1]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: capped vehicle surplus return',
   [16, [['EV0', 10, 0], ['EV3', 16, 2], ['EV1', 6, 2], ['EV2', 5, 1]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 0], ['EV3', 10]]],
  ['regression: capped vehicle surplus return (partial repair)',
   [40, [['EV0', 16, 0], ['EV2', 16, 2], ['EV3', 8, 2], ['EV1', 6, 1]]],
   [['EV0', 13], ['EV1', 6], ['EV2', 13], ['EV3', 8]]],
  ['control 1',
   [30,
    [['EV1', 8, 3], ['EV4', 6, 2], ['EV0', 16, 0], ['EV2', 10, 3], ['EV3', 24, 1], ['EV5', 6, 2]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 6]]],
  ['control 2', [40, [['EV1', 5, 1], ['EV0', 32, 2]]], [['EV0', 32], ['EV1', 0]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: capped vehicle surplus return',
   [16, [['EV0', 6, 1], ['EV2', 5, 1], ['EV1', 24, 3]]], [['EV0', 6], ['EV1', 10], ['EV2', 0]]],
  ['regression: capped vehicle surplus return (partial repair)',
   [40, [['EV1', 16, 0], ['EV2', 10, 2], ['EV3', 10, 3], ['EV4', 8, 1], ['EV0', 24, 1]]],
   [['EV0', 8], ['EV1', 8], ['EV2', 8], ['EV3', 8], ['EV4', 8]]],
  ['control 1', [18, [['EV2', 32, 0], ['EV0', 5, 2], ['EV1', 24, 3]]],
   [['EV0', 0], ['EV1', 9], ['EV2', 9]]],
  ['control 2', [16, [['EV0', 24, 3], ['EV1', 16, 0], ['EV2', 16, 2]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 8]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: capped vehicle surplus return',
   [48, [['EV2', 8, 2], ['EV0', 32, 3], ['EV1', 5, 3]]], [['EV0', 32], ['EV1', 0], ['EV2', 8]]],
  ['regression: capped vehicle surplus return (partial repair)',
   [32, [['EV1', 8, 1], ['EV2', 32, 0], ['EV0', 32, 1]]], [['EV0', 12], ['EV1', 8], ['EV2', 12]]],
  ['control 1', [16, [['EV1', 16, 2], ['EV0', 32, 3]]], [['EV0', 8], ['EV1', 8]]],
  ['control 2',
   [48,
    [['EV3', 8, 0], ['EV1', 16, 0], ['EV4', 5, 0], ['EV2', 8, 0], ['EV5', 10, 0], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 12], ['EV2', 8], ['EV3', 8], ['EV4', 0], ['EV5', 10]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: capped vehicle surplus return',
   [40, [['EV1', 24, 3], ['EV0', 6, 0], ['EV2', 32, 1], ['EV3', 32, 3]]],
   [['EV0', 6], ['EV1', 12], ['EV2', 11], ['EV3', 11]]],
  ['regression: capped vehicle surplus return (partial repair)',
   [40,
    [['EV0', 5, 0], ['EV2', 24, 3], ['EV1', 32, 0], ['EV5', 8, 2], ['EV3', 10, 2], ['EV4', 8, 1]]],
   [['EV0', 0], ['EV1', 8], ['EV2', 8], ['EV3', 8], ['EV4', 8], ['EV5', 8]]],
  ['control 1', [40, [['EV2', 5, 0], ['EV0', 6, 2], ['EV3', 24, 2], ['EV1', 10, 3]]],
   [['EV0', 6], ['EV1', 10], ['EV2', 0], ['EV3', 24]]],
  ['control 2', [10, [['EV0', 10, 0]]], [['EV0', 10]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(limit_a, evs):
    elig = [e for e in evs if e[1] >= 6]
    elig.sort(key=lambda e: (-e[2], e[0]))
    admitted = []
    for e in elig:
        if 6 * (len(admitted) + 1) <= limit_a:
            admitted.append(e)
    alloc = {e[0]: 0 for e in evs}
    remaining = limit_a
    open_ = list(admitted)
    while open_:
        share = remaining // len(open_)
        capped = [e for e in open_ if e[1] <= share]
        if not capped:
            for e in open_:
                alloc[e[0]] = share
            remaining -= share * len(open_)
            break
        for e in capped:
            alloc[e[0]] = e[1]
            remaining -= 6
            open_.remove(e)
    for e in admitted:
        if remaining <= 0:
            break
        if alloc[e[0]] < e[1]:
            alloc[e[0]] += 1
            remaining -= 1
    return [[k, alloc[k]] for k in sorted(alloc)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: capped vehicle surplus return',
   [63,
    [['EV4', 24, 3], ['EV5', 8, 1], ['EV2', 6, 0], ['EV3', 5, 1], ['EV1', 5, 3], ['EV0', 24, 3]]],
   [['EV0', 24], ['EV1', 0], ['EV2', 6], ['EV3', 0], ['EV4', 24], ['EV5', 8]]],
  ['regression: capped vehicle surplus return (partial repair)',
   [30, [['EV0', 8, 0], ['EV1', 16, 3], ['EV2', 32, 0]]], [['EV0', 8], ['EV1', 11], ['EV2', 11]]],
  ['control 1', [32, [['EV0', 32, 3], ['EV1', 24, 3]]], [['EV0', 16], ['EV1', 16]]],
  ['control 2', [24, [['EV0', 16, 2], ['EV1', 32, 2], ['EV2', 32, 0], ['EV3', 8, 1]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: capped vehicle surplus return',
   [16, [['EV0', 10, 0], ['EV3', 16, 2], ['EV1', 6, 2], ['EV2', 5, 1]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 0], ['EV3', 10]]],
  ['regression: capped vehicle surplus return (partial repair)',
   [40, [['EV0', 16, 0], ['EV2', 16, 2], ['EV3', 8, 2], ['EV1', 6, 1]]],
   [['EV0', 13], ['EV1', 6], ['EV2', 13], ['EV3', 8]]],
  ['control 1',
   [30,
    [['EV1', 8, 3], ['EV4', 6, 2], ['EV0', 16, 0], ['EV2', 10, 3], ['EV3', 24, 1], ['EV5', 6, 2]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 6]]],
  ['control 2', [40, [['EV1', 5, 1], ['EV0', 32, 2]]], [['EV0', 32], ['EV1', 0]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: capped vehicle surplus return',
   [16, [['EV0', 6, 1], ['EV2', 5, 1], ['EV1', 24, 3]]], [['EV0', 6], ['EV1', 10], ['EV2', 0]]],
  ['regression: capped vehicle surplus return (partial repair)',
   [40, [['EV1', 16, 0], ['EV2', 10, 2], ['EV3', 10, 3], ['EV4', 8, 1], ['EV0', 24, 1]]],
   [['EV0', 8], ['EV1', 8], ['EV2', 8], ['EV3', 8], ['EV4', 8]]],
  ['control 1', [18, [['EV2', 32, 0], ['EV0', 5, 2], ['EV1', 24, 3]]],
   [['EV0', 0], ['EV1', 9], ['EV2', 9]]],
  ['control 2', [16, [['EV0', 24, 3], ['EV1', 16, 0], ['EV2', 16, 2]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 8]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: capped vehicle surplus return',
   [48, [['EV2', 8, 2], ['EV0', 32, 3], ['EV1', 5, 3]]], [['EV0', 32], ['EV1', 0], ['EV2', 8]]],
  ['regression: capped vehicle surplus return (partial repair)',
   [32, [['EV1', 8, 1], ['EV2', 32, 0], ['EV0', 32, 1]]], [['EV0', 12], ['EV1', 8], ['EV2', 12]]],
  ['control 1', [16, [['EV1', 16, 2], ['EV0', 32, 3]]], [['EV0', 8], ['EV1', 8]]],
  ['control 2',
   [48,
    [['EV3', 8, 0], ['EV1', 16, 0], ['EV4', 5, 0], ['EV2', 8, 0], ['EV5', 10, 0], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 12], ['EV2', 8], ['EV3', 8], ['EV4', 0], ['EV5', 10]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: capped vehicle surplus return',
   [40, [['EV1', 24, 3], ['EV0', 6, 0], ['EV2', 32, 1], ['EV3', 32, 3]]],
   [['EV0', 6], ['EV1', 12], ['EV2', 11], ['EV3', 11]]],
  ['regression: capped vehicle surplus return (partial repair)',
   [40,
    [['EV0', 5, 0], ['EV2', 24, 3], ['EV1', 32, 0], ['EV5', 8, 2], ['EV3', 10, 2], ['EV4', 8, 1]]],
   [['EV0', 0], ['EV1', 8], ['EV2', 8], ['EV3', 8], ['EV4', 8], ['EV5', 8]]],
  ['control 1', [40, [['EV2', 5, 0], ['EV0', 6, 2], ['EV3', 24, 2], ['EV1', 10, 3]]],
   [['EV0', 6], ['EV1', 10], ['EV2', 0], ['EV3', 24]]],
  ['control 2', [10, [['EV0', 10, 0]]], [['EV0', 10]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Amps released by vehicles with low onboard limits are not given to other vehicles.

evs is a list of [id, max_a, priority]. An EV with max_a < 6 cannot be served. Eligible EVs are ordered by priority descending then id; each is admitted while 6*(admitted+1) <= limit_a. Admitted EVs are water-filled: repeatedly give floor(remaining/open) amps, fixing EVs whose max_a <= share at their max. Leftover amps go one each in admission order to EVs below max. Return [[id, amps]] for every EV sorted by id (0 = paused).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(limit_a, evs):
    elig = [e for e in evs if e[1] >= 6]
    elig.sort(key=lambda e: (-e[2], e[0]))
    admitted = []
    for e in elig:
        if 6 * (len(admitted) + 1) <= limit_a:
            admitted.append(e)
    alloc = {e[0]: 0 for e in evs}
    remaining = limit_a
    open_ = list(admitted)
    while open_:
        share = remaining // len(open_)
        capped = [e for e in open_ if e[1] <= share]
        if not capped:
            for e in open_:
                alloc[e[0]] = share
            remaining -= share * len(open_)
            break
        for e in capped:
            alloc[e[0]] = e[1]
            remaining -= e[1]
            open_.remove(e)
    for e in admitted:
        if remaining <= 0:
            break
        if alloc[e[0]] <= e[1]:
            alloc[e[0]] += 1
            remaining -= 1
    return [[k, alloc[k]] for k in sorted(alloc)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover amp ceiling', [30, [['EV0', 16, 1]]], [['EV0', 16]]],
  ['regression: leftover amp ceiling (partial repair)',
   [63,
    [['EV4', 24, 3], ['EV5', 8, 1], ['EV2', 6, 0], ['EV3', 5, 1], ['EV1', 5, 3], ['EV0', 24, 3]]],
   [['EV0', 24], ['EV1', 0], ['EV2', 6], ['EV3', 0], ['EV4', 24], ['EV5', 8]]],
  ['control 1', [32, [['EV0', 32, 3], ['EV1', 24, 3]]], [['EV0', 16], ['EV1', 16]]],
  ['control 2', [24, [['EV0', 16, 2], ['EV1', 32, 2], ['EV2', 32, 0], ['EV3', 8, 1]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover amp ceiling', [32, [['EV2', 8, 3], ['EV1', 16, 1], ['EV0', 5, 3]]],
   [['EV0', 0], ['EV1', 16], ['EV2', 8]]],
  ['regression: leftover amp ceiling (partial repair)',
   [63,
    [['EV2', 16, 0], ['EV1', 24, 2], ['EV0', 6, 1], ['EV5', 6, 1], ['EV3', 32, 3], ['EV4', 16, 1]]],
   [['EV0', 6], ['EV1', 13], ['EV2', 12], ['EV3', 13], ['EV4', 13], ['EV5', 6]]],
  ['control 1',
   [30,
    [['EV1', 8, 3], ['EV4', 6, 2], ['EV0', 16, 0], ['EV2', 10, 3], ['EV3', 24, 1], ['EV5', 6, 2]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 6]]],
  ['control 2', [40, [['EV1', 5, 1], ['EV0', 32, 2]]], [['EV0', 32], ['EV1', 0]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover amp ceiling', [30, [['EV0', 24, 1]]], [['EV0', 24]]],
  ['regression: leftover amp ceiling (partial repair)', [63, [['EV1', 10, 1], ['EV0', 32, 0]]],
   [['EV0', 32], ['EV1', 10]]],
  ['control 1', [18, [['EV2', 32, 0], ['EV0', 5, 2], ['EV1', 24, 3]]],
   [['EV0', 0], ['EV1', 9], ['EV2', 9]]],
  ['control 2', [16, [['EV0', 24, 3], ['EV1', 16, 0], ['EV2', 16, 2]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 8]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover amp ceiling', [40, [['EV0', 16, 0]]], [['EV0', 16]]],
  ['regression: leftover amp ceiling (partial repair)', [63, [['EV1', 24, 1], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 24]]],
  ['control 1', [16, [['EV1', 16, 2], ['EV0', 32, 3]]], [['EV0', 8], ['EV1', 8]]],
  ['control 2',
   [48,
    [['EV3', 8, 0], ['EV1', 16, 0], ['EV4', 5, 0], ['EV2', 8, 0], ['EV5', 10, 0], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 12], ['EV2', 8], ['EV3', 8], ['EV4', 0], ['EV5', 10]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover amp ceiling', [48, [['EV0', 16, 3]]], [['EV0', 16]]],
  ['regression: leftover amp ceiling (partial repair)', [16, [['EV0', 8, 1]]], [['EV0', 8]]],
  ['control 1', [40, [['EV2', 5, 0], ['EV0', 6, 2], ['EV3', 24, 2], ['EV1', 10, 3]]],
   [['EV0', 6], ['EV1', 10], ['EV2', 0], ['EV3', 24]]],
  ['control 2', [10, [['EV0', 10, 0]]], [['EV0', 10]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(limit_a, evs):
    elig = [e for e in evs if e[1] >= 6]
    elig.sort(key=lambda e: (-e[2], e[0]))
    admitted = []
    for e in elig:
        if 6 * (len(admitted) + 1) <= limit_a:
            admitted.append(e)
    alloc = {e[0]: 0 for e in evs}
    remaining = limit_a
    open_ = list(admitted)
    while open_:
        share = remaining // len(open_)
        capped = [e for e in open_ if e[1] <= share]
        if not capped:
            for e in open_:
                alloc[e[0]] = share
            remaining -= share * len(open_)
            break
        for e in capped:
            alloc[e[0]] = e[1]
            remaining -= e[1]
            open_.remove(e)
    for e in admitted:
        if remaining <= 0:
            break
        if alloc[e[0]] != 0:
            alloc[e[0]] += 1
            remaining -= 1
    return [[k, alloc[k]] for k in sorted(alloc)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover amp ceiling', [30, [['EV0', 16, 1]]], [['EV0', 16]]],
  ['regression: leftover amp ceiling (partial repair)',
   [63,
    [['EV4', 24, 3], ['EV5', 8, 1], ['EV2', 6, 0], ['EV3', 5, 1], ['EV1', 5, 3], ['EV0', 24, 3]]],
   [['EV0', 24], ['EV1', 0], ['EV2', 6], ['EV3', 0], ['EV4', 24], ['EV5', 8]]],
  ['control 1', [32, [['EV0', 32, 3], ['EV1', 24, 3]]], [['EV0', 16], ['EV1', 16]]],
  ['control 2', [24, [['EV0', 16, 2], ['EV1', 32, 2], ['EV2', 32, 0], ['EV3', 8, 1]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover amp ceiling', [32, [['EV2', 8, 3], ['EV1', 16, 1], ['EV0', 5, 3]]],
   [['EV0', 0], ['EV1', 16], ['EV2', 8]]],
  ['regression: leftover amp ceiling (partial repair)',
   [63,
    [['EV2', 16, 0], ['EV1', 24, 2], ['EV0', 6, 1], ['EV5', 6, 1], ['EV3', 32, 3], ['EV4', 16, 1]]],
   [['EV0', 6], ['EV1', 13], ['EV2', 12], ['EV3', 13], ['EV4', 13], ['EV5', 6]]],
  ['control 1',
   [30,
    [['EV1', 8, 3], ['EV4', 6, 2], ['EV0', 16, 0], ['EV2', 10, 3], ['EV3', 24, 1], ['EV5', 6, 2]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 6]]],
  ['control 2', [40, [['EV1', 5, 1], ['EV0', 32, 2]]], [['EV0', 32], ['EV1', 0]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover amp ceiling', [30, [['EV0', 24, 1]]], [['EV0', 24]]],
  ['regression: leftover amp ceiling (partial repair)', [63, [['EV1', 10, 1], ['EV0', 32, 0]]],
   [['EV0', 32], ['EV1', 10]]],
  ['control 1', [18, [['EV2', 32, 0], ['EV0', 5, 2], ['EV1', 24, 3]]],
   [['EV0', 0], ['EV1', 9], ['EV2', 9]]],
  ['control 2', [16, [['EV0', 24, 3], ['EV1', 16, 0], ['EV2', 16, 2]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 8]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover amp ceiling', [40, [['EV0', 16, 0]]], [['EV0', 16]]],
  ['regression: leftover amp ceiling (partial repair)', [63, [['EV1', 24, 1], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 24]]],
  ['control 1', [16, [['EV1', 16, 2], ['EV0', 32, 3]]], [['EV0', 8], ['EV1', 8]]],
  ['control 2',
   [48,
    [['EV3', 8, 0], ['EV1', 16, 0], ['EV4', 5, 0], ['EV2', 8, 0], ['EV5', 10, 0], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 12], ['EV2', 8], ['EV3', 8], ['EV4', 0], ['EV5', 10]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover amp ceiling', [48, [['EV0', 16, 3]]], [['EV0', 16]]],
  ['regression: leftover amp ceiling (partial repair)', [16, [['EV0', 8, 1]]], [['EV0', 8]]],
  ['control 1', [40, [['EV2', 5, 0], ['EV0', 6, 2], ['EV3', 24, 2], ['EV1', 10, 3]]],
   [['EV0', 6], ['EV1', 10], ['EV2', 0], ['EV3', 24]]],
  ['control 2', [10, [['EV0', 10, 0]]], [['EV0', 10]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A vehicle is commanded one amp above the limit it advertised.

evs is a list of [id, max_a, priority]. An EV with max_a < 6 cannot be served. Eligible EVs are ordered by priority descending then id; each is admitted while 6*(admitted+1) <= limit_a. Admitted EVs are water-filled: repeatedly give floor(remaining/open) amps, fixing EVs whose max_a <= share at their max. Leftover amps go one each in admission order to EVs below max. Return [[id, amps]] for every EV sorted by id (0 = paused).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(limit_a, evs):
    elig = [e for e in evs if e[1] >= 6]
    elig.sort(key=lambda e: (-e[2], e[0]))
    admitted = []
    for e in elig:
        if 6 * (len(admitted) + 1) <= limit_a:
            admitted.append(e)
    alloc = {e[0]: 0 for e in evs}
    remaining = limit_a
    open_ = list(admitted)
    while open_:
        share = remaining // len(open_)
        capped = [e for e in open_ if e[1] <= share]
        if not capped:
            for e in open_:
                alloc[e[0]] = share
            remaining -= share * len(open_)
            break
        for e in capped:
            alloc[e[0]] = e[1]
            remaining -= e[1]
            open_.remove(e)
    for e in evs:
        if remaining <= 0:
            break
        if alloc[e[0]] < e[1]:
            alloc[e[0]] += 1
            remaining -= 1
    return [[k, alloc[k]] for k in sorted(alloc)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover recipients',
   [63,
    [['EV4', 24, 3], ['EV5', 8, 1], ['EV2', 6, 0], ['EV3', 5, 1], ['EV1', 5, 3], ['EV0', 24, 3]]],
   [['EV0', 24], ['EV1', 0], ['EV2', 6], ['EV3', 0], ['EV4', 24], ['EV5', 8]]],
  ['regression: leftover recipients (partial repair)',
   [30,
    [['EV5', 24, 2], ['EV2', 32, 3], ['EV0', 5, 1], ['EV1', 5, 2], ['EV4', 24, 3], ['EV3', 16, 2]]],
   [['EV0', 0], ['EV1', 0], ['EV2', 8], ['EV3', 7], ['EV4', 8], ['EV5', 7]]],
  ['control 1', [32, [['EV0', 32, 3], ['EV1', 24, 3]]], [['EV0', 16], ['EV1', 16]]],
  ['control 2', [24, [['EV0', 16, 2], ['EV1', 32, 2], ['EV2', 32, 0], ['EV3', 8, 1]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover recipients',
   [32,
    [['EV2', 32, 1], ['EV4', 32, 0], ['EV3', 6, 2], ['EV1', 32, 2], ['EV5', 24, 1],
     ['EV0', 32, 3]]],
   [['EV0', 7], ['EV1', 7], ['EV2', 6], ['EV3', 6], ['EV4', 0], ['EV5', 6]]],
  ['regression: leftover recipients (partial repair)',
   [63,
    [['EV2', 16, 0], ['EV1', 24, 2], ['EV0', 6, 1], ['EV5', 6, 1], ['EV3', 32, 3], ['EV4', 16, 1]]],
   [['EV0', 6], ['EV1', 13], ['EV2', 12], ['EV3', 13], ['EV4', 13], ['EV5', 6]]],
  ['control 1',
   [30,
    [['EV1', 8, 3], ['EV4', 6, 2], ['EV0', 16, 0], ['EV2', 10, 3], ['EV3', 24, 1], ['EV5', 6, 2]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 6]]],
  ['control 2', [40, [['EV1', 5, 1], ['EV0', 32, 2]]], [['EV0', 32], ['EV1', 0]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover recipients',
   [48, [['EV1', 16, 2], ['EV0', 16, 2], ['EV4', 32, 3], ['EV2', 24, 3], ['EV3', 24, 3]]],
   [['EV0', 9], ['EV1', 9], ['EV2', 10], ['EV3', 10], ['EV4', 10]]],
  ['regression: leftover recipients (partial repair)',
   [32, [['EV0', 32, 0], ['EV2', 24, 0], ['EV3', 10, 1], ['EV4', 6, 1], ['EV1', 5, 3]]],
   [['EV0', 9], ['EV1', 0], ['EV2', 8], ['EV3', 9], ['EV4', 6]]],
  ['control 1', [18, [['EV2', 32, 0], ['EV0', 5, 2], ['EV1', 24, 3]]],
   [['EV0', 0], ['EV1', 9], ['EV2', 9]]],
  ['control 2', [16, [['EV0', 24, 3], ['EV1', 16, 0], ['EV2', 16, 2]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 8]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover recipients', [48, [['EV2', 8, 2], ['EV0', 32, 3], ['EV1', 5, 3]]],
   [['EV0', 32], ['EV1', 0], ['EV2', 8]]],
  ['regression: leftover recipients (partial repair)',
   [48, [['EV3', 16, 3], ['EV2', 6, 0], ['EV4', 16, 0], ['EV1', 16, 2], ['EV0', 32, 2]]],
   [['EV0', 11], ['EV1', 10], ['EV2', 6], ['EV3', 11], ['EV4', 10]]],
  ['control 1', [16, [['EV1', 16, 2], ['EV0', 32, 3]]], [['EV0', 8], ['EV1', 8]]],
  ['control 2',
   [48,
    [['EV3', 8, 0], ['EV1', 16, 0], ['EV4', 5, 0], ['EV2', 8, 0], ['EV5', 10, 0], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 12], ['EV2', 8], ['EV3', 8], ['EV4', 0], ['EV5', 10]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover recipients',
   [32, [['EV1', 10, 3], ['EV2', 5, 1], ['EV3', 10, 0], ['EV0', 8, 2]]],
   [['EV0', 8], ['EV1', 10], ['EV2', 0], ['EV3', 10]]],
  ['regression: leftover recipients (partial repair)',
   [63, [['EV0', 16, 3], ['EV4', 16, 3], ['EV1', 32, 1], ['EV3', 24, 2], ['EV2', 16, 0]]],
   [['EV0', 13], ['EV1', 12], ['EV2', 12], ['EV3', 13], ['EV4', 13]]],
  ['control 1', [40, [['EV2', 5, 0], ['EV0', 6, 2], ['EV3', 24, 2], ['EV1', 10, 3]]],
   [['EV0', 6], ['EV1', 10], ['EV2', 0], ['EV3', 24]]],
  ['control 2', [10, [['EV0', 10, 0]]], [['EV0', 10]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(limit_a, evs):
    elig = [e for e in evs if e[1] >= 6]
    elig.sort(key=lambda e: (-e[2], e[0]))
    admitted = []
    for e in elig:
        if 6 * (len(admitted) + 1) <= limit_a:
            admitted.append(e)
    alloc = {e[0]: 0 for e in evs}
    remaining = limit_a
    open_ = list(admitted)
    while open_:
        share = remaining // len(open_)
        capped = [e for e in open_ if e[1] <= share]
        if not capped:
            for e in open_:
                alloc[e[0]] = share
            remaining -= share * len(open_)
            break
        for e in capped:
            alloc[e[0]] = e[1]
            remaining -= e[1]
            open_.remove(e)
    for e in sorted(admitted, key=lambda e: e[0]):
        if remaining <= 0:
            break
        if alloc[e[0]] < e[1]:
            alloc[e[0]] += 1
            remaining -= 1
    return [[k, alloc[k]] for k in sorted(alloc)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover recipients',
   [63,
    [['EV4', 24, 3], ['EV5', 8, 1], ['EV2', 6, 0], ['EV3', 5, 1], ['EV1', 5, 3], ['EV0', 24, 3]]],
   [['EV0', 24], ['EV1', 0], ['EV2', 6], ['EV3', 0], ['EV4', 24], ['EV5', 8]]],
  ['regression: leftover recipients (partial repair)',
   [30,
    [['EV5', 24, 2], ['EV2', 32, 3], ['EV0', 5, 1], ['EV1', 5, 2], ['EV4', 24, 3], ['EV3', 16, 2]]],
   [['EV0', 0], ['EV1', 0], ['EV2', 8], ['EV3', 7], ['EV4', 8], ['EV5', 7]]],
  ['control 1', [32, [['EV0', 32, 3], ['EV1', 24, 3]]], [['EV0', 16], ['EV1', 16]]],
  ['control 2', [24, [['EV0', 16, 2], ['EV1', 32, 2], ['EV2', 32, 0], ['EV3', 8, 1]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover recipients',
   [32,
    [['EV2', 32, 1], ['EV4', 32, 0], ['EV3', 6, 2], ['EV1', 32, 2], ['EV5', 24, 1],
     ['EV0', 32, 3]]],
   [['EV0', 7], ['EV1', 7], ['EV2', 6], ['EV3', 6], ['EV4', 0], ['EV5', 6]]],
  ['regression: leftover recipients (partial repair)',
   [63,
    [['EV2', 16, 0], ['EV1', 24, 2], ['EV0', 6, 1], ['EV5', 6, 1], ['EV3', 32, 3], ['EV4', 16, 1]]],
   [['EV0', 6], ['EV1', 13], ['EV2', 12], ['EV3', 13], ['EV4', 13], ['EV5', 6]]],
  ['control 1',
   [30,
    [['EV1', 8, 3], ['EV4', 6, 2], ['EV0', 16, 0], ['EV2', 10, 3], ['EV3', 24, 1], ['EV5', 6, 2]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 6]]],
  ['control 2', [40, [['EV1', 5, 1], ['EV0', 32, 2]]], [['EV0', 32], ['EV1', 0]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover recipients',
   [48, [['EV1', 16, 2], ['EV0', 16, 2], ['EV4', 32, 3], ['EV2', 24, 3], ['EV3', 24, 3]]],
   [['EV0', 9], ['EV1', 9], ['EV2', 10], ['EV3', 10], ['EV4', 10]]],
  ['regression: leftover recipients (partial repair)',
   [32, [['EV0', 32, 0], ['EV2', 24, 0], ['EV3', 10, 1], ['EV4', 6, 1], ['EV1', 5, 3]]],
   [['EV0', 9], ['EV1', 0], ['EV2', 8], ['EV3', 9], ['EV4', 6]]],
  ['control 1', [18, [['EV2', 32, 0], ['EV0', 5, 2], ['EV1', 24, 3]]],
   [['EV0', 0], ['EV1', 9], ['EV2', 9]]],
  ['control 2', [16, [['EV0', 24, 3], ['EV1', 16, 0], ['EV2', 16, 2]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 8]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover recipients', [48, [['EV2', 8, 2], ['EV0', 32, 3], ['EV1', 5, 3]]],
   [['EV0', 32], ['EV1', 0], ['EV2', 8]]],
  ['regression: leftover recipients (partial repair)',
   [48, [['EV3', 16, 3], ['EV2', 6, 0], ['EV4', 16, 0], ['EV1', 16, 2], ['EV0', 32, 2]]],
   [['EV0', 11], ['EV1', 10], ['EV2', 6], ['EV3', 11], ['EV4', 10]]],
  ['control 1', [16, [['EV1', 16, 2], ['EV0', 32, 3]]], [['EV0', 8], ['EV1', 8]]],
  ['control 2',
   [48,
    [['EV3', 8, 0], ['EV1', 16, 0], ['EV4', 5, 0], ['EV2', 8, 0], ['EV5', 10, 0], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 12], ['EV2', 8], ['EV3', 8], ['EV4', 0], ['EV5', 10]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: leftover recipients',
   [32, [['EV1', 10, 3], ['EV2', 5, 1], ['EV3', 10, 0], ['EV0', 8, 2]]],
   [['EV0', 8], ['EV1', 10], ['EV2', 0], ['EV3', 10]]],
  ['regression: leftover recipients (partial repair)',
   [63, [['EV0', 16, 3], ['EV4', 16, 3], ['EV1', 32, 1], ['EV3', 24, 2], ['EV2', 16, 0]]],
   [['EV0', 13], ['EV1', 12], ['EV2', 12], ['EV3', 13], ['EV4', 13]]],
  ['control 1', [40, [['EV2', 5, 0], ['EV0', 6, 2], ['EV3', 24, 2], ['EV1', 10, 3]]],
   [['EV0', 6], ['EV1', 10], ['EV2', 0], ['EV3', 24]]],
  ['control 2', [10, [['EV0', 10, 0]]], [['EV0', 10]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Paused vehicles receive a 1 A setpoint, below the minimum pilot current.

evs is a list of [id, max_a, priority]. An EV with max_a < 6 cannot be served. Eligible EVs are ordered by priority descending then id; each is admitted while 6*(admitted+1) <= limit_a. Admitted EVs are water-filled: repeatedly give floor(remaining/open) amps, fixing EVs whose max_a <= share at their max. Leftover amps go one each in admission order to EVs below max. Return [[id, amps]] for every EV sorted by id (0 = paused).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(limit_a, evs):
    elig = [e for e in evs if e[1] >= 6]
    elig.sort(key=lambda e: (-e[2], e[0]))
    admitted = []
    for e in elig:
        if 6 * (len(admitted) + 1) <= limit_a:
            admitted.append(e)
    alloc = {e[0]: 0 for e in evs}
    remaining = limit_a
    open_ = list(admitted)
    while open_:
        share = round(remaining / len(open_))
        capped = [e for e in open_ if e[1] <= share]
        if not capped:
            for e in open_:
                alloc[e[0]] = share
            remaining -= share * len(open_)
            break
        for e in capped:
            alloc[e[0]] = e[1]
            remaining -= e[1]
            open_.remove(e)
    for e in admitted:
        if remaining <= 0:
            break
        if alloc[e[0]] < e[1]:
            alloc[e[0]] += 1
            remaining -= 1
    return [[k, alloc[k]] for k in sorted(alloc)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: equal share rounding',
   [63, [['EV0', 16, 3], ['EV1', 6, 3], ['EV4', 6, 3], ['EV2', 24, 3], ['EV3', 32, 0]]],
   [['EV0', 16], ['EV1', 6], ['EV2', 18], ['EV3', 17], ['EV4', 6]]],
  ['regression: equal share rounding (partial repair)',
   [32,
    [['EV0', 6, 2], ['EV5', 32, 2], ['EV3', 10, 3], ['EV1', 32, 3], ['EV2', 16, 0],
     ['EV4', 10, 2]]],
   [['EV0', 6], ['EV1', 7], ['EV2', 0], ['EV3', 7], ['EV4', 6], ['EV5', 6]]],
  ['control 1', [32, [['EV0', 32, 3], ['EV1', 24, 3]]], [['EV0', 16], ['EV1', 16]]],
  ['control 2', [24, [['EV0', 16, 2], ['EV1', 32, 2], ['EV2', 32, 0], ['EV3', 8, 1]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: equal share rounding',
   [63,
    [['EV2', 16, 0], ['EV1', 24, 2], ['EV0', 6, 1], ['EV5', 6, 1], ['EV3', 32, 3], ['EV4', 16, 1]]],
   [['EV0', 6], ['EV1', 13], ['EV2', 12], ['EV3', 13], ['EV4', 13], ['EV5', 6]]],
  ['regression: equal share rounding (partial repair)',
   [32,
    [['EV2', 32, 1], ['EV4', 32, 0], ['EV3', 6, 2], ['EV1', 32, 2], ['EV5', 24, 1],
     ['EV0', 32, 3]]],
   [['EV0', 7], ['EV1', 7], ['EV2', 6], ['EV3', 6], ['EV4', 0], ['EV5', 6]]],
  ['control 1',
   [30,
    [['EV1', 8, 3], ['EV4', 6, 2], ['EV0', 16, 0], ['EV2', 10, 3], ['EV3', 24, 1], ['EV5', 6, 2]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 6]]],
  ['control 2', [40, [['EV1', 5, 1], ['EV0', 32, 2]]], [['EV0', 32], ['EV1', 0]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: equal share rounding',
   [48, [['EV1', 16, 2], ['EV0', 16, 2], ['EV4', 32, 3], ['EV2', 24, 3], ['EV3', 24, 3]]],
   [['EV0', 9], ['EV1', 9], ['EV2', 10], ['EV3', 10], ['EV4', 10]]],
  ['regression: equal share rounding (partial repair)',
   [32, [['EV0', 32, 0], ['EV2', 24, 0], ['EV3', 10, 1], ['EV4', 6, 1], ['EV1', 5, 3]]],
   [['EV0', 9], ['EV1', 0], ['EV2', 8], ['EV3', 9], ['EV4', 6]]],
  ['control 1', [18, [['EV2', 32, 0], ['EV0', 5, 2], ['EV1', 24, 3]]],
   [['EV0', 0], ['EV1', 9], ['EV2', 9]]],
  ['control 2', [16, [['EV0', 24, 3], ['EV1', 16, 0], ['EV2', 16, 2]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 8]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: equal share rounding',
   [32, [['EV0', 32, 1], ['EV3', 24, 1], ['EV1', 16, 2], ['EV2', 6, 2]]],
   [['EV0', 9], ['EV1', 9], ['EV2', 6], ['EV3', 8]]],
  ['regression: equal share rounding (partial repair)',
   [48, [['EV3', 16, 3], ['EV2', 6, 0], ['EV4', 16, 0], ['EV1', 16, 2], ['EV0', 32, 2]]],
   [['EV0', 11], ['EV1', 10], ['EV2', 6], ['EV3', 11], ['EV4', 10]]],
  ['control 1', [16, [['EV1', 16, 2], ['EV0', 32, 3]]], [['EV0', 8], ['EV1', 8]]],
  ['control 2',
   [48,
    [['EV3', 8, 0], ['EV1', 16, 0], ['EV4', 5, 0], ['EV2', 8, 0], ['EV5', 10, 0], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 12], ['EV2', 8], ['EV3', 8], ['EV4', 0], ['EV5', 10]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: equal share rounding',
   [63, [['EV0', 16, 3], ['EV4', 16, 3], ['EV1', 32, 1], ['EV3', 24, 2], ['EV2', 16, 0]]],
   [['EV0', 13], ['EV1', 12], ['EV2', 12], ['EV3', 13], ['EV4', 13]]],
  ['regression: equal share rounding (partial repair)',
   [40, [['EV1', 24, 3], ['EV0', 6, 0], ['EV2', 32, 1], ['EV3', 32, 3]]],
   [['EV0', 6], ['EV1', 12], ['EV2', 11], ['EV3', 11]]],
  ['control 1', [40, [['EV2', 5, 0], ['EV0', 6, 2], ['EV3', 24, 2], ['EV1', 10, 3]]],
   [['EV0', 6], ['EV1', 10], ['EV2', 0], ['EV3', 24]]],
  ['control 2', [10, [['EV0', 10, 0]]], [['EV0', 10]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(limit_a, evs):
    elig = [e for e in evs if e[1] >= 6]
    elig.sort(key=lambda e: (-e[2], e[0]))
    admitted = []
    for e in elig:
        if 6 * (len(admitted) + 1) <= limit_a:
            admitted.append(e)
    alloc = {e[0]: 0 for e in evs}
    remaining = limit_a
    open_ = list(admitted)
    while open_:
        share = -(-remaining // len(open_))
        capped = [e for e in open_ if e[1] <= share]
        if not capped:
            for e in open_:
                alloc[e[0]] = share
            remaining -= share * len(open_)
            break
        for e in capped:
            alloc[e[0]] = e[1]
            remaining -= e[1]
            open_.remove(e)
    for e in admitted:
        if remaining <= 0:
            break
        if alloc[e[0]] < e[1]:
            alloc[e[0]] += 1
            remaining -= 1
    return [[k, alloc[k]] for k in sorted(alloc)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: equal share rounding',
   [63, [['EV0', 16, 3], ['EV1', 6, 3], ['EV4', 6, 3], ['EV2', 24, 3], ['EV3', 32, 0]]],
   [['EV0', 16], ['EV1', 6], ['EV2', 18], ['EV3', 17], ['EV4', 6]]],
  ['regression: equal share rounding (partial repair)',
   [32,
    [['EV0', 6, 2], ['EV5', 32, 2], ['EV3', 10, 3], ['EV1', 32, 3], ['EV2', 16, 0],
     ['EV4', 10, 2]]],
   [['EV0', 6], ['EV1', 7], ['EV2', 0], ['EV3', 7], ['EV4', 6], ['EV5', 6]]],
  ['control 1', [32, [['EV0', 32, 3], ['EV1', 24, 3]]], [['EV0', 16], ['EV1', 16]]],
  ['control 2', [24, [['EV0', 16, 2], ['EV1', 32, 2], ['EV2', 32, 0], ['EV3', 8, 1]]],
   [['EV0', 6], ['EV1', 6], ['EV2', 6], ['EV3', 6]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: equal share rounding',
   [63,
    [['EV2', 16, 0], ['EV1', 24, 2], ['EV0', 6, 1], ['EV5', 6, 1], ['EV3', 32, 3], ['EV4', 16, 1]]],
   [['EV0', 6], ['EV1', 13], ['EV2', 12], ['EV3', 13], ['EV4', 13], ['EV5', 6]]],
  ['regression: equal share rounding (partial repair)',
   [32,
    [['EV2', 32, 1], ['EV4', 32, 0], ['EV3', 6, 2], ['EV1', 32, 2], ['EV5', 24, 1],
     ['EV0', 32, 3]]],
   [['EV0', 7], ['EV1', 7], ['EV2', 6], ['EV3', 6], ['EV4', 0], ['EV5', 6]]],
  ['control 1',
   [30,
    [['EV1', 8, 3], ['EV4', 6, 2], ['EV0', 16, 0], ['EV2', 10, 3], ['EV3', 24, 1], ['EV5', 6, 2]]],
   [['EV0', 0], ['EV1', 6], ['EV2', 6], ['EV3', 6], ['EV4', 6], ['EV5', 6]]],
  ['control 2', [40, [['EV1', 5, 1], ['EV0', 32, 2]]], [['EV0', 32], ['EV1', 0]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: equal share rounding',
   [48, [['EV1', 16, 2], ['EV0', 16, 2], ['EV4', 32, 3], ['EV2', 24, 3], ['EV3', 24, 3]]],
   [['EV0', 9], ['EV1', 9], ['EV2', 10], ['EV3', 10], ['EV4', 10]]],
  ['regression: equal share rounding (partial repair)',
   [32, [['EV0', 32, 0], ['EV2', 24, 0], ['EV3', 10, 1], ['EV4', 6, 1], ['EV1', 5, 3]]],
   [['EV0', 9], ['EV1', 0], ['EV2', 8], ['EV3', 9], ['EV4', 6]]],
  ['control 1', [18, [['EV2', 32, 0], ['EV0', 5, 2], ['EV1', 24, 3]]],
   [['EV0', 0], ['EV1', 9], ['EV2', 9]]],
  ['control 2', [16, [['EV0', 24, 3], ['EV1', 16, 0], ['EV2', 16, 2]]],
   [['EV0', 8], ['EV1', 0], ['EV2', 8]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: equal share rounding',
   [32, [['EV0', 32, 1], ['EV3', 24, 1], ['EV1', 16, 2], ['EV2', 6, 2]]],
   [['EV0', 9], ['EV1', 9], ['EV2', 6], ['EV3', 8]]],
  ['regression: equal share rounding (partial repair)',
   [48, [['EV3', 16, 3], ['EV2', 6, 0], ['EV4', 16, 0], ['EV1', 16, 2], ['EV0', 32, 2]]],
   [['EV0', 11], ['EV1', 10], ['EV2', 6], ['EV3', 11], ['EV4', 10]]],
  ['control 1', [16, [['EV1', 16, 2], ['EV0', 32, 3]]], [['EV0', 8], ['EV1', 8]]],
  ['control 2',
   [48,
    [['EV3', 8, 0], ['EV1', 16, 0], ['EV4', 5, 0], ['EV2', 8, 0], ['EV5', 10, 0], ['EV0', 10, 3]]],
   [['EV0', 10], ['EV1', 12], ['EV2', 8], ['EV3', 8], ['EV4', 0], ['EV5', 10]]]],
 [['boundary: exactly one minimum share', [6, [['A', 32, 0], ['B', 32, 0]]], [['A', 6], ['B', 0]]],
  ['boundary: EV at 6 A maximum', [20, [['A', 6, 0], ['B', 32, 0]]], [['A', 6], ['B', 14]]],
  ['boundary: no EVs', [32, []], []],
  ['regression: equal share rounding',
   [63, [['EV0', 16, 3], ['EV4', 16, 3], ['EV1', 32, 1], ['EV3', 24, 2], ['EV2', 16, 0]]],
   [['EV0', 13], ['EV1', 12], ['EV2', 12], ['EV3', 13], ['EV4', 13]]],
  ['regression: equal share rounding (partial repair)',
   [40, [['EV1', 24, 3], ['EV0', 6, 0], ['EV2', 32, 1], ['EV3', 32, 3]]],
   [['EV0', 6], ['EV1', 12], ['EV2', 11], ['EV3', 11]]],
  ['control 1', [40, [['EV2', 5, 0], ['EV0', 6, 2], ['EV3', 24, 2], ['EV1', 10, 3]]],
   [['EV0', 6], ['EV1', 10], ['EV2', 0], ['EV3', 24]]],
  ['control 2', [10, [['EV0', 10, 0]]], [['EV0', 10]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The sum of commanded currents exceeds the circuit breaker limit.

evs is a list of [id, max_a, priority]. An EV with max_a < 6 cannot be served. Eligible EVs are ordered by priority descending then id; each is admitted while 6*(admitted+1) <= limit_a. Admitted EVs are water-filled: repeatedly give floor(remaining/open) amps, fixing EVs whose max_a <= share at their max. Leftover amps go one each in admission order to EVs below max. Return [[id, amps]] for every EV sorted by id (0 = paused).

split: open-access