StripeOA #2
Merchant Fraud Score
Estimated MediumJudge-ready
Topics (AI-labelled)SimulationHashing
Given the day's transactions, the rule for each transaction, and each merchant's base score, compute each merchant's final risk score in three independent steps: first apply amount multipliers, then the bonus for customer transaction frequency, and finally the penalty for same-hour frequency. When the 3rd transaction reaches the frequency threshold, the additive factor or penalty of each of the group's first 3 transactions is applied retroactively; from the 4th transaction on, only that transaction's own value is applied. Every step processes the full transaction list independently, in the order multiplier, bonus, penalty.
The source example's transaction list was missing a comma between items 4 and 5; this site fixes that formatting error and keeps the 6 transactions and 6 rules.
Input
The first line contains n (1..1000). The next n lines are transactions: merchant_id,amount,customer_id,hour. Then come n lines of rules, matched to the transactions by index: min_transaction_amount,multiplicative_factor,additive_factor,penalty. Next is a line with m (1..1000), followed by m lines of merchants: merchant_id,base_score. Identifiers are 1..32 ASCII characters other than commas; amounts and rule values are signed 64-bit integers, and all intermediate scores are guaranteed not to overflow; hour is 0..23, and base_score is 1..50. The merchant_id of every transaction must be in the merchant list, and no merchant ID is repeated.
Output
First output the number of merchants m; then output merchant_id,<final score> line by line in lexicographic order of merchant_id.
Example 1
Input:
6
merchant1,1200,customer1,10
merchant1,500,customer1,10
merchant2,2400,customer1,15
merchant1,800,customer1,16
merchant1,1000,customer2,17
merchant1,1400,customer1,10
1000,2,8,15
1400,5,3,19
2300,3,17,3
1800,2,9,6
1000,4,8,2
1200,3,11,7
2
merchant1,10
merchant2,20
Output:
2
merchant1,50
merchant2,60
Example 2
Input:
1
a,100,c,8
100,7,0,0
1
a,5
Output:
1
a,5
Example 3
Input:
1
z,101,c,23
100,2,4,10
2
z,3
empty,9
Output:
2
empty,9
z,6
Editorial
Loading solution…