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

N = 1
observations = []
def solve(x):
    bal = dict(x['members'])
    sent = dict(x['sent_ytd'])
    out = []
    for f, t, p in x['transfers']:
        if f == t or f not in bal or t not in bal:
            out.append('invalid')
            continue
        if p < x['min_transfer']:
            out.append('below minimum')
            continue
        if sent.get(f, 0) + p >= x['annual_cap']:
            out.append('cap')
            continue
        fee = (p * x['fee_bp'] + 9999) // 10000
        if bal[f] < p + fee:
            out.append('insufficient')
            continue
        bal[f] -= p + fee
        bal[t] += p
        sent[f] = sent.get(f, 0) + p
        out.append(fee)
    return {'results': out, 'balances': [[k, bal[k]] for k in sorted(bal)]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2000]], 'sent_ytd': {}}, {'results': [50], 'balances': [['a', 2950], ['b', 2100]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1001]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1013], ['b', 1001]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14999}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5001]], 'sent_ytd': {'a': 14999}}, {'results': [126], 'balances': [['a', 84873], ['b', 5001]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1004], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48962], ['b', 1011]]}], ['fees do not use cap', {'fee_bp': 501, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [501, 501], 'balances': [['a', 68998], ['c', 20000]]}], ['one over cap', {'fee_bp': 0, 'min_transfer': 1, 'annual_cap': 100, 'members': {'a': 500, 'b': 0}, 'transfers': [['a', 'b', 100]], 'sent_ytd': {'a': 1}}, {'results': ['cap'], 'balances': [['a', 500], ['b', 0]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2001]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2948], ['b', 2101]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1002]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1012], ['b', 1002]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14998}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5002]], 'sent_ytd': {'a': 14998}}, {'results': [126], 'balances': [['a', 84872], ['b', 5002]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1007], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48959], ['b', 1014]]}], ['fees do not use cap', {'fee_bp': 502, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [502, 502], 'balances': [['a', 68996], ['c', 20000]]}], ['one over cap', {'fee_bp': 0, 'min_transfer': 1, 'annual_cap': 100, 'members': {'a': 500, 'b': 0}, 'transfers': [['a', 'b', 99]], 'sent_ytd': {'a': 2}}, {'results': ['cap'], 'balances': [['a', 500], ['b', 0]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2002]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2947], ['b', 2102]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1003]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1011], ['b', 1003]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14997}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5003]], 'sent_ytd': {'a': 14997}}, {'results': [126], 'balances': [['a', 84871], ['b', 5003]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1010], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48956], ['b', 1017]]}], ['fees do not use cap', {'fee_bp': 503, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [503, 503], 'balances': [['a', 68994], ['c', 20000]]}], ['one over cap', {'fee_bp': 0, 'min_transfer': 1, 'annual_cap': 100, 'members': {'a': 500, 'b': 0}, 'transfers': [['a', 'b', 98]], 'sent_ytd': {'a': 3}}, {'results': ['cap'], 'balances': [['a', 500], ['b', 0]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2003]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2946], ['b', 2103]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1004]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1010], ['b', 1004]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14996}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5004]], 'sent_ytd': {'a': 14996}}, {'results': [126], 'balances': [['a', 84870], ['b', 5004]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1013], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48953], ['b', 1020]]}], ['fees do not use cap', {'fee_bp': 504, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [504, 504], 'balances': [['a', 68992], ['c', 20000]]}], ['one over cap', {'fee_bp': 0, 'min_transfer': 1, 'annual_cap': 100, 'members': {'a': 500, 'b': 0}, 'transfers': [['a', 'b', 97]], 'sent_ytd': {'a': 4}}, {'results': ['cap'], 'balances': [['a', 500], ['b', 0]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2004]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2945], ['b', 2104]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1005]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1009], ['b', 1005]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14995}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5005]], 'sent_ytd': {'a': 14995}}, {'results': [126], 'balances': [['a', 84869], ['b', 5005]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1016], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48950], ['b', 1023]]}], ['fees do not use cap', {'fee_bp': 505, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [505, 505], 'balances': [['a', 68990], ['c', 20000]]}], ['one over cap', {'fee_bp': 0, 'min_transfer': 1, 'annual_cap': 100, 'members': {'a': 500, 'b': 0}, 'transfers': [['a', 'b', 96]], 'sent_ytd': {'a': 5}}, {'results': ['cap'], 'balances': [['a', 500], ['b', 0]]}]]]
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(x):
    bal = dict(x['members'])
    sent = dict(x['sent_ytd'])
    out = []
    for f, t, p in x['transfers']:
        if f == t or f not in bal or t not in bal:
            out.append('invalid')
            continue
        if p < x['min_transfer']:
            out.append('below minimum')
            continue
        if sent.get(f, 0) + p > x['annual_cap'] + 1:
            out.append('cap')
            continue
        fee = (p * x['fee_bp'] + 9999) // 10000
        if bal[f] < p + fee:
            out.append('insufficient')
            continue
        bal[f] -= p + fee
        bal[t] += p
        sent[f] = sent.get(f, 0) + p
        out.append(fee)
    return {'results': out, 'balances': [[k, bal[k]] for k in sorted(bal)]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2000]], 'sent_ytd': {}}, {'results': [50], 'balances': [['a', 2950], ['b', 2100]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1001]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1013], ['b', 1001]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14999}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5001]], 'sent_ytd': {'a': 14999}}, {'results': [126], 'balances': [['a', 84873], ['b', 5001]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1004], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48962], ['b', 1011]]}], ['fees do not use cap', {'fee_bp': 501, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [501, 501], 'balances': [['a', 68998], ['c', 20000]]}], ['one over cap', {'fee_bp': 0, 'min_transfer': 1, 'annual_cap': 100, 'members': {'a': 500, 'b': 0}, 'transfers': [['a', 'b', 100]], 'sent_ytd': {'a': 1}}, {'results': ['cap'], 'balances': [['a', 500], ['b', 0]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2001]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2948], ['b', 2101]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1002]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1012], ['b', 1002]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14998}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5002]], 'sent_ytd': {'a': 14998}}, {'results': [126], 'balances': [['a', 84872], ['b', 5002]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1007], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48959], ['b', 1014]]}], ['fees do not use cap', {'fee_bp': 502, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [502, 502], 'balances': [['a', 68996], ['c', 20000]]}], ['one over cap', {'fee_bp': 0, 'min_transfer': 1, 'annual_cap': 100, 'members': {'a': 500, 'b': 0}, 'transfers': [['a', 'b', 99]], 'sent_ytd': {'a': 2}}, {'results': ['cap'], 'balances': [['a', 500], ['b', 0]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2002]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2947], ['b', 2102]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1003]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1011], ['b', 1003]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14997}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5003]], 'sent_ytd': {'a': 14997}}, {'results': [126], 'balances': [['a', 84871], ['b', 5003]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1010], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48956], ['b', 1017]]}], ['fees do not use cap', {'fee_bp': 503, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [503, 503], 'balances': [['a', 68994], ['c', 20000]]}], ['one over cap', {'fee_bp': 0, 'min_transfer': 1, 'annual_cap': 100, 'members': {'a': 500, 'b': 0}, 'transfers': [['a', 'b', 98]], 'sent_ytd': {'a': 3}}, {'results': ['cap'], 'balances': [['a', 500], ['b', 0]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2003]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2946], ['b', 2103]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1004]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1010], ['b', 1004]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14996}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5004]], 'sent_ytd': {'a': 14996}}, {'results': [126], 'balances': [['a', 84870], ['b', 5004]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1013], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48953], ['b', 1020]]}], ['fees do not use cap', {'fee_bp': 504, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [504, 504], 'balances': [['a', 68992], ['c', 20000]]}], ['one over cap', {'fee_bp': 0, 'min_transfer': 1, 'annual_cap': 100, 'members': {'a': 500, 'b': 0}, 'transfers': [['a', 'b', 97]], 'sent_ytd': {'a': 4}}, {'results': ['cap'], 'balances': [['a', 500], ['b', 0]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2004]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2945], ['b', 2104]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1005]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1009], ['b', 1005]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14995}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5005]], 'sent_ytd': {'a': 14995}}, {'results': [126], 'balances': [['a', 84869], ['b', 5005]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1016], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48950], ['b', 1023]]}], ['fees do not use cap', {'fee_bp': 505, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [505, 505], 'balances': [['a', 68990], ['c', 20000]]}], ['one over cap', {'fee_bp': 0, 'min_transfer': 1, 'annual_cap': 100, 'members': {'a': 500, 'b': 0}, 'transfers': [['a', 'b', 96]], 'sent_ytd': {'a': 5}}, {'results': ['cap'], 'balances': [['a', 500], ['b', 0]]}]]]
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 transfer that brings the year total exactly to the cap is refused.

Input {members:{id:balance}, transfers:[[from,to,pts]], fee_bp, min_transfer, annual_cap, sent_ytd}. Self transfers or unknown members are "invalid"; pts below the minimum are "below minimum"; sent_ytd + pts above annual_cap is "cap" (fees do not count toward the cap). The fee is ceil(pts*fee_bp/10000) points charged to the sender, who must hold pts + fee ("insufficient" otherwise). The recipient receives pts. Return {results (fee or reason), balances:[[id,bal]] sorted}.

split: open-access


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

N = 1
observations = []
def solve(x):
    st = []
    ns = []
    for p in x['promos']:
        if p['kind'] == 'multiplier':
            e = x['base'] * p['value'] // 100
        else:
            e = p['value']
        if p['cap'] > 0:
            e = min(e, p['cap'])
        (st if p['stackable'] else ns).append([e, p['id']])
    bonus = sum(e for e, _ in st)
    applied = [i for _, i in st]
    if ns:
        best = min(ns, key=lambda r: (-r[0], r[1]))
        bonus += best[0]
        applied.append(best[1])
    return {'bonus': bonus, 'applied': sorted(applied)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed promos', {'base': 1001, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1501, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2501}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3001, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 101, 'stackable': True, 'cap': 0}]}, {'bonus': 301, 'applied': [3, 9]}], ['no promos', {'base': 10, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 111, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 77, 'applied': [5]}], ['odd base', {'base': 334, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 333, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 501, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 531, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1002, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1503, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2502}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3002, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 102, 'stackable': True, 'cap': 0}]}, {'bonus': 302, 'applied': [3, 9]}], ['no promos', {'base': 20, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 112, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 84, 'applied': [5]}], ['odd base', {'base': 335, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 334, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 502, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 532, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1003, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1504, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2503}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3003, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 103, 'stackable': True, 'cap': 0}]}, {'bonus': 303, 'applied': [3, 9]}], ['no promos', {'base': 30, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 113, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 91, 'applied': [5]}], ['odd base', {'base': 336, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 336, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 503, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 533, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1004, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1506, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2504}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3004, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 104, 'stackable': True, 'cap': 0}]}, {'bonus': 304, 'applied': [3, 9]}], ['no promos', {'base': 40, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 114, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 98, 'applied': [5]}], ['odd base', {'base': 337, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 336, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 504, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 534, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1005, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1507, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2505}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3005, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 105, 'stackable': True, 'cap': 0}]}, {'bonus': 305, 'applied': [3, 9]}], ['no promos', {'base': 50, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 115, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 105, 'applied': [5]}], ['odd base', {'base': 338, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 337, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 505, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 535, 'applied': [1, 2, 3]}]]]
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(x):
    st = []
    ns = []
    for p in x['promos']:
        if p['kind'] == 'multiplier':
            e = (x['base'] * p['value'] - 100) // 100
        else:
            e = p['value']
        if p['cap'] > 0:
            e = min(e, p['cap'])
        (st if p['stackable'] else ns).append([e, p['id']])
    bonus = sum(e for e, _ in st)
    applied = [i for _, i in st]
    if ns:
        best = min(ns, key=lambda r: (-r[0], r[1]))
        bonus += best[0]
        applied.append(best[1])
    return {'bonus': bonus, 'applied': sorted(applied)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed promos', {'base': 1001, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1501, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2501}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3001, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 101, 'stackable': True, 'cap': 0}]}, {'bonus': 301, 'applied': [3, 9]}], ['no promos', {'base': 10, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 111, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 77, 'applied': [5]}], ['odd base', {'base': 334, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 333, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 501, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 531, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1002, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1503, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2502}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3002, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 102, 'stackable': True, 'cap': 0}]}, {'bonus': 302, 'applied': [3, 9]}], ['no promos', {'base': 20, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 112, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 84, 'applied': [5]}], ['odd base', {'base': 335, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 334, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 502, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 532, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1003, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1504, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2503}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3003, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 103, 'stackable': True, 'cap': 0}]}, {'bonus': 303, 'applied': [3, 9]}], ['no promos', {'base': 30, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 113, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 91, 'applied': [5]}], ['odd base', {'base': 336, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 336, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 503, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 533, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1004, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1506, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2504}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3004, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 104, 'stackable': True, 'cap': 0}]}, {'bonus': 304, 'applied': [3, 9]}], ['no promos', {'base': 40, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 114, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 98, 'applied': [5]}], ['odd base', {'base': 337, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 336, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 504, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 534, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1005, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1507, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2505}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3005, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 105, 'stackable': True, 'cap': 0}]}, {'bonus': 305, 'applied': [3, 9]}], ['no promos', {'base': 50, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 115, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 105, 'applied': [5]}], ['odd base', {'base': 338, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 337, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 505, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 535, 'applied': [1, 2, 3]}]]]
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 double-points promo awards triple points in total.

Input {base, promos:[{id,kind,value,stackable,cap}]}. A multiplier promo (value in percent) gives floor(base*(value-100)/100) extra; a fixed promo gives value. Each extra is capped at cap when cap > 0. All stackable extras apply; of the non-stackable promos only the single best capped extra applies (ties to the lower id), in addition to the stackable ones. Return {bonus, applied ids sorted}.

split: open-access


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

N = 1
observations = []
def solve(x):
    st = []
    ns = []
    for p in x['promos']:
        if p['kind'] == 'multiplier':
            e = x['base'] * (p['value'] - 100) // 100
        else:
            e = p['value']
        if True:
            e = min(e, p['cap'])
        (st if p['stackable'] else ns).append([e, p['id']])
    bonus = sum(e for e, _ in st)
    applied = [i for _, i in st]
    if ns:
        best = min(ns, key=lambda r: (-r[0], r[1]))
        bonus += best[0]
        applied.append(best[1])
    return {'bonus': bonus, 'applied': sorted(applied)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed promos', {'base': 1001, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1501, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2501}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3001, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 101, 'stackable': True, 'cap': 0}]}, {'bonus': 301, 'applied': [3, 9]}], ['no promos', {'base': 10, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 111, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 77, 'applied': [5]}], ['odd base', {'base': 334, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 333, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 501, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 531, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1002, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1503, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2502}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3002, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 102, 'stackable': True, 'cap': 0}]}, {'bonus': 302, 'applied': [3, 9]}], ['no promos', {'base': 20, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 112, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 84, 'applied': [5]}], ['odd base', {'base': 335, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 334, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 502, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 532, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1003, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1504, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2503}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3003, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 103, 'stackable': True, 'cap': 0}]}, {'bonus': 303, 'applied': [3, 9]}], ['no promos', {'base': 30, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 113, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 91, 'applied': [5]}], ['odd base', {'base': 336, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 336, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 503, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 533, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1004, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1506, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2504}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3004, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 104, 'stackable': True, 'cap': 0}]}, {'bonus': 304, 'applied': [3, 9]}], ['no promos', {'base': 40, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 114, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 98, 'applied': [5]}], ['odd base', {'base': 337, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 336, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 504, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 534, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1005, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1507, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2505}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3005, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 105, 'stackable': True, 'cap': 0}]}, {'bonus': 305, 'applied': [3, 9]}], ['no promos', {'base': 50, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 115, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 105, 'applied': [5]}], ['odd base', {'base': 338, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 337, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 505, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 535, 'applied': [1, 2, 3]}]]]
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(x):
    st = []
    ns = []
    for p in x['promos']:
        if p['kind'] == 'multiplier':
            e = x['base'] * (p['value'] - 100) // 100
        else:
            e = p['value']
        if p['cap'] > 0 and p['kind'] == 'multiplier':
            e = min(e, p['cap'])
        (st if p['stackable'] else ns).append([e, p['id']])
    bonus = sum(e for e, _ in st)
    applied = [i for _, i in st]
    if ns:
        best = min(ns, key=lambda r: (-r[0], r[1]))
        bonus += best[0]
        applied.append(best[1])
    return {'bonus': bonus, 'applied': sorted(applied)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed promos', {'base': 1001, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1501, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2501}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3001, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 101, 'stackable': True, 'cap': 0}]}, {'bonus': 301, 'applied': [3, 9]}], ['no promos', {'base': 10, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 111, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 77, 'applied': [5]}], ['odd base', {'base': 334, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 333, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 501, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 531, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1002, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1503, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2502}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3002, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 102, 'stackable': True, 'cap': 0}]}, {'bonus': 302, 'applied': [3, 9]}], ['no promos', {'base': 20, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 112, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 84, 'applied': [5]}], ['odd base', {'base': 335, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 334, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 502, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 532, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1003, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1504, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2503}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3003, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 103, 'stackable': True, 'cap': 0}]}, {'bonus': 303, 'applied': [3, 9]}], ['no promos', {'base': 30, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 113, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 91, 'applied': [5]}], ['odd base', {'base': 336, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 336, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 503, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 533, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1004, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1506, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2504}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3004, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 104, 'stackable': True, 'cap': 0}]}, {'bonus': 304, 'applied': [3, 9]}], ['no promos', {'base': 40, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 114, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 98, 'applied': [5]}], ['odd base', {'base': 337, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 336, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 504, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 534, 'applied': [1, 2, 3]}]], [['mixed promos', {'base': 1005, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1507, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2505}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3005, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 105, 'stackable': True, 'cap': 0}]}, {'bonus': 305, 'applied': [3, 9]}], ['no promos', {'base': 50, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 115, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 105, 'applied': [5]}], ['odd base', {'base': 338, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 337, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 505, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 535, 'applied': [1, 2, 3]}]]]
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:
Promotions with no cap award zero bonus points.

Input {base, promos:[{id,kind,value,stackable,cap}]}. A multiplier promo (value in percent) gives floor(base*(value-100)/100) extra; a fixed promo gives value. Each extra is capped at cap when cap > 0. All stackable extras apply; of the non-stackable promos only the single best capped extra applies (ties to the lower id), in addition to the stackable ones. Return {bonus, applied ids sorted}.

split: open-access


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

N = 1
observations = []
def solve(x):
    st = []
    ns = []
    for p in x['promos']:
        if p['kind'] == 'multiplier':
            e = x['base'] * (p['value'] - 100) // 100
        else:
            e = p['value']
        if p['cap'] > 0:
            e = min(e, p['cap'])
        (st if p['stackable'] else ns).append([e, p['id']])
    bonus = sum(e for e, _ in st)
    applied = [i for _, i in st]
    if ns:
        best = ns[0]
        bonus += best[0]
        applied.append(best[1])
    return {'bonus': bonus, 'applied': sorted(applied)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed promos', {'base': 1001, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1501, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2501}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3001, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 101, 'stackable': True, 'cap': 0}]}, {'bonus': 301, 'applied': [3, 9]}], ['no promos', {'base': 10, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 111, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 77, 'applied': [5]}], ['odd base', {'base': 334, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 333, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 501, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 531, 'applied': [1, 2, 3]}], ['richer later', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 5, 'stackable': False, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 51, 'stackable': False, 'cap': 0}]}, {'bonus': 51, 'applied': [2]}]], [['mixed promos', {'base': 1002, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1503, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2502}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3002, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 102, 'stackable': True, 'cap': 0}]}, {'bonus': 302, 'applied': [3, 9]}], ['no promos', {'base': 20, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 112, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 84, 'applied': [5]}], ['odd base', {'base': 335, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 334, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 502, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 532, 'applied': [1, 2, 3]}], ['richer later', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 5, 'stackable': False, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 52, 'stackable': False, 'cap': 0}]}, {'bonus': 52, 'applied': [2]}]], [['mixed promos', {'base': 1003, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1504, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2503}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3003, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 103, 'stackable': True, 'cap': 0}]}, {'bonus': 303, 'applied': [3, 9]}], ['no promos', {'base': 30, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 113, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 91, 'applied': [5]}], ['odd base', {'base': 336, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 336, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 503, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 533, 'applied': [1, 2, 3]}], ['richer later', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 5, 'stackable': False, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 53, 'stackable': False, 'cap': 0}]}, {'bonus': 53, 'applied': [2]}]], [['mixed promos', {'base': 1004, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1506, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2504}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3004, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 104, 'stackable': True, 'cap': 0}]}, {'bonus': 304, 'applied': [3, 9]}], ['no promos', {'base': 40, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 114, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 98, 'applied': [5]}], ['odd base', {'base': 337, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 336, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 504, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 534, 'applied': [1, 2, 3]}], ['richer later', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 5, 'stackable': False, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 54, 'stackable': False, 'cap': 0}]}, {'bonus': 54, 'applied': [2]}]], [['mixed promos', {'base': 1005, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1507, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2505}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3005, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 105, 'stackable': True, 'cap': 0}]}, {'bonus': 305, 'applied': [3, 9]}], ['no promos', {'base': 50, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 115, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 105, 'applied': [5]}], ['odd base', {'base': 338, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 337, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 505, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 535, 'applied': [1, 2, 3]}], ['richer later', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 5, 'stackable': False, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 55, 'stackable': False, 'cap': 0}]}, {'bonus': 55, 'applied': [2]}]]]
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(x):
    st = []
    ns = []
    for p in x['promos']:
        if p['kind'] == 'multiplier':
            e = x['base'] * (p['value'] - 100) // 100
        else:
            e = p['value']
        if p['cap'] > 0:
            e = min(e, p['cap'])
        (st if p['stackable'] else ns).append([e, p['id']])
    bonus = sum(e for e, _ in st)
    applied = [i for _, i in st]
    if ns:
        best = max(ns)
        bonus += best[0]
        applied.append(best[1])
    return {'bonus': bonus, 'applied': sorted(applied)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed promos', {'base': 1001, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1501, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2501}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3001, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 101, 'stackable': True, 'cap': 0}]}, {'bonus': 301, 'applied': [3, 9]}], ['no promos', {'base': 10, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 111, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 77, 'applied': [5]}], ['odd base', {'base': 334, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 333, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 501, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 531, 'applied': [1, 2, 3]}], ['richer later', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 5, 'stackable': False, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 51, 'stackable': False, 'cap': 0}]}, {'bonus': 51, 'applied': [2]}]], [['mixed promos', {'base': 1002, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1503, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2502}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3002, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 102, 'stackable': True, 'cap': 0}]}, {'bonus': 302, 'applied': [3, 9]}], ['no promos', {'base': 20, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 112, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 84, 'applied': [5]}], ['odd base', {'base': 335, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 334, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 502, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 532, 'applied': [1, 2, 3]}], ['richer later', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 5, 'stackable': False, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 52, 'stackable': False, 'cap': 0}]}, {'bonus': 52, 'applied': [2]}]], [['mixed promos', {'base': 1003, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1504, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2503}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3003, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 103, 'stackable': True, 'cap': 0}]}, {'bonus': 303, 'applied': [3, 9]}], ['no promos', {'base': 30, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 113, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 91, 'applied': [5]}], ['odd base', {'base': 336, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 336, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 503, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 533, 'applied': [1, 2, 3]}], ['richer later', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 5, 'stackable': False, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 53, 'stackable': False, 'cap': 0}]}, {'bonus': 53, 'applied': [2]}]], [['mixed promos', {'base': 1004, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1506, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2504}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3004, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 104, 'stackable': True, 'cap': 0}]}, {'bonus': 304, 'applied': [3, 9]}], ['no promos', {'base': 40, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 114, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 98, 'applied': [5]}], ['odd base', {'base': 337, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 336, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 504, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 534, 'applied': [1, 2, 3]}], ['richer later', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 5, 'stackable': False, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 54, 'stackable': False, 'cap': 0}]}, {'bonus': 54, 'applied': [2]}]], [['mixed promos', {'base': 1005, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 200, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 300, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}]}, {'bonus': 1507, 'applied': [1, 3]}], ['caps', {'base': 2000, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 300, 'stackable': True, 'cap': 2505}, {'id': 2, 'kind': 'fixed', 'value': 900, 'stackable': True, 'cap': 500}]}, {'bonus': 3005, 'applied': [1, 2]}], ['tie on value', {'base': 400, 'promos': [{'id': 7, 'kind': 'fixed', 'value': 200, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'multiplier', 'value': 150, 'stackable': False, 'cap': 0}, {'id': 9, 'kind': 'fixed', 'value': 105, 'stackable': True, 'cap': 0}]}, {'bonus': 305, 'applied': [3, 9]}], ['no promos', {'base': 50, 'promos': []}, {'bonus': 0, 'applied': []}], ['only non stackable', {'base': 700, 'promos': [{'id': 4, 'kind': 'fixed', 'value': 50, 'stackable': False, 'cap': 0}, {'id': 5, 'kind': 'multiplier', 'value': 115, 'stackable': False, 'cap': 0}, {'id': 6, 'kind': 'fixed', 'value': 60, 'stackable': False, 'cap': 40}]}, {'bonus': 105, 'applied': [5]}], ['odd base', {'base': 338, 'promos': [{'id': 1, 'kind': 'multiplier', 'value': 125, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'multiplier', 'value': 175, 'stackable': True, 'cap': 0}]}, {'bonus': 337, 'applied': [1, 2]}], ['best beats stack', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 10, 'stackable': True, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 505, 'stackable': False, 'cap': 0}, {'id': 3, 'kind': 'fixed', 'value': 20, 'stackable': True, 'cap': 0}]}, {'bonus': 535, 'applied': [1, 2, 3]}], ['richer later', {'base': 100, 'promos': [{'id': 1, 'kind': 'fixed', 'value': 5, 'stackable': False, 'cap': 0}, {'id': 2, 'kind': 'fixed', 'value': 55, 'stackable': False, 'cap': 0}]}, {'bonus': 55, 'applied': [2]}]]]
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 first listed non-stackable promo applies even when a richer one exists.

Input {base, promos:[{id,kind,value,stackable,cap}]}. A multiplier promo (value in percent) gives floor(base*(value-100)/100) extra; a fixed promo gives value. Each extra is capped at cap when cap > 0. All stackable extras apply; of the non-stackable promos only the single best capped extra applies (ties to the lower id), in addition to the stackable ones. Return {bonus, applied ids sorted}.

split: open-access