Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
986 B
8
Indexable
Never
users = [200, 200, 200, 200, 200, 100, 100, 100, 100]
rewards = [
    {"min_pt_claim": 400, "id": 4, "remaining": 2},
    {"min_pt_claim": 300, "id": 3, "remaining": 2},
    {"min_pt_claim": 200, "id": 2, "remaining": 1},
    {"min_pt_claim": 100, "id": 1, "remaining": 1},
]

n = len(users)
cur_reward_idx = 0
cur_user_idx = 0
while cur_reward_idx < len(rewards) and cur_user_idx < len(users):
    if users[cur_user_idx] < rewards[cur_reward_idx]["min_pt_claim"]:
        # print("not sufficient point")
        cur_reward_idx += 1
        continue
    if rewards[cur_reward_idx]["remaining"] == 0:
        # print("not sufficient reward")
        cur_reward_idx += 1
        continue
    # If user has sufficient points & rewards are sufficient
    # claimRewardForUser(id: i, rewardId: cur_reward.id)
    print(
        f"claimed reward for user {cur_user_idx} with rewardId: {rewards[cur_reward_idx]['id']}"
    )
    rewards[cur_reward_idx]["remaining"] -= 1
    cur_user_idx += 1