Find the optimal matching algorithm of pointing coupons?

problem description

this is a coupon module

there are three kinds of coupons: designated merchandise coupons, supplier coupons, all-purpose coupons;

you can only use one coupon per order

use precedence rules

1, the amount is the largest and meets the conditions to give priority to use

2, if the amount is the same, priority will be given to the specified product-designated supplier-GM will use it from high to low priority

now suppose I settle goods An and B from two different suppliers in the shopping cart at the same time ( different suppliers will make separate orders ). Now I have two eligible coupons, a coupon for specified A goods is 20 yuan, and a full-court coupon is 30 yuan. According to the previous rules, A goods will be automatically selected to use full-court coupons, and B will not be able to use coupons.

but if A uses a 20% coupon, B can also use a general coupon. I"m stuck here--

ask the boss for advice! I am a little scum, I am eager for progress!

Php
Apr.06,2021

Let's talk about the algorithm. The following python pseudo code
order array A (A0, A1.An) n, coupon array B (B0 Magi B1.Bm), where B0 (amount, type), type: A0~An or c0~ck designated supplier or M universal.

-sharphashmap, 
d = {}
for i in B:
    if i[1] in d:
        bisect.insort(d[i[1]], i[0]) -sharp
    else:
        d[i[1]] = [i[0]] -sharp 
-sharpO(mlogk) (k<=m)
-sharpAAhashmap
a = {} -sharpkeyvalue
for i in A:
    if i in d:
        a[i] = d[i][0] -sharp
        d[i].pop(0)
    else:
        a[i] = 0 -sharp0
-sharpO(n)
-sharp
-sharpC (C0,...Ck) C0value (A0,..At)
for c in C:
    r = sorted([(a[i], i) for i in C[c]], lambda x: x[0]) -sharp 
    if not r:
        continue -sharp
    rindex = 0
    while d[c]: -sharp
        if d[c][0] <= r[rindex][0]:
            break -sharp
        a[r[rindex][1]] = d[c][0] -sharp
        rindex += 1
        d[c].pop(0)
-sharpO(k.tlogt)
-sharp
r = sorted([(a[i], i) for i in a], lambda x: x[0])-sharp 
rindex = 0
while d['M']: -sharp 
    if d['M'][0] <= r[rindex][0]:
        break -sharp
    a[r[rindex][1]] = d['M'][0] -sharp
    rindex += 1
    d['M'].pop(0)
    
print(a) -sharp
-sharpO(nlogn)

-sharptnm

first of all, your rules are not clear: do you prefer the coupon with the largest amount or the narrowest use?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b2a6-2c26a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b2a6-2c26a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?