Implement a safeguard logic that ensures the seller’s wallet balance cannot fall into a negative state.
Use safeguard_wallet(initial_balance, transactions). transactions is an array of signed integers: positive values add funds and negative values request debits. Process transactions in order, accept a transaction only if the resulting balance is non-negative, and return the final balance plus a Boolean acceptance result for every transaction.
Example 1: initial_balance = 100, transactions = [-30, -80, 50] returns {"final_balance": 120, "accepted": [true, false, true]}.
Example 2: initial_balance = 0, transactions = [-1, 10] returns {"final_balance": 10, "accepted": [false, true]}.
Constraints: the initial balance and transaction values are integers, the initial balance is non-negative, and transaction count is at most 10^5.
def safeguard_wallet(initial_balance, transactions):