A neighborhood coffee subscription club logs every order its members place, each order tagged with the billing cycle it fell in. Membership renewal is offered only to members who prove they are actively engaged: a member qualifies for renewal only if their total order value (quantity multiplied by unit price, summed over every order they placed in that cycle) reaches at least a renewal threshold in BOTH of two specified cycles — cycle A and cycle B. Orders placed in any other cycle should be ignored for this check. Each member id always maps to exactly one member name across all of their orders. Given the full order log, the renewal threshold, and the two cycle tags, report every qualifying member.
Line 1: four space-separated tokens: n threshold cycleA cycleB — n is the number of order records, threshold is the minimum required cycle spend, and cycleA / cycleB are the two cycle tags to check (cycleA != cycleB). Next n lines: each contains five space-separated tokens: id name cycle quantity price — the member id, member name, the cycle tag this order was placed in, the quantity of items ordered, and the price per item.
Print one line per qualifying member, formatted as "id name", ordered by ascending id. A member qualifies only if their total order value in cycleA is >= threshold AND their total order value in cycleB is >= threshold. Print nothing if no member qualifies.
Example 1
Input
6 100 M6 M7 1 Alice M6 5 10 1 Alice M6 5 10 1 Alice M7 2 60 2 Bob M6 1 50 2 Bob M7 3 50 3 Cara M6 10 20
Expected
1 Alice
Explanation
Alice (id 1) placed two orders in cycle M6 totaling 5*10 + 5*10 = 100, meeting the threshold of 100, and one order in cycle M7 totaling 2*60 = 120, also meeting the threshold — so Alice qualifies. Bob (id 2) has only 1*50 = 50 in M6, which falls short of the 100 threshold, so Bob is disqualified even though his M7 total (3*50=150) clears it. Cara (id 3) has 10*20=200 in M6 but placed no order in M7 at all, so her M7 total is 0, which fails the threshold. Only Alice qualifies, so the output is '1 Alice'.
Example 2
Input
4 1000 X Y 1 Dave X 2 10 1 Dave Y 2 10 2 Eve X 100 50 2 Eve Y 1 5
Expected
(empty)Explanation
Dave (id 1) totals 2*10=20 in cycle X and 2*10=20 in cycle Y, both far below the 1000 threshold, so Dave fails both checks. Eve (id 2) totals 100*50=5000 in cycle X, clearing the threshold, but only 1*5=5 in cycle Y, which fails — so Eve is disqualified for not meeting BOTH cycles. No member qualifies, so nothing is printed.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →