← 返回 openai 的题目列表AccountBalance Class with Time-Based Grants and Spending
类型:online_judge
openai
Implement an AccountBalance class with the following three methods: addGrant, addSpend, and getBalance. Each method includes a timestamp indicating when the add, spend, or getBalance operation is executed. The Grant also includes an expiration time. Specific requirements are as follows:
The addGrant(amount: float, timestamp: int, expire: int) method is used to add a grant amount with a specified expiration time.
The addSpend(amount: float, timestamp: int) method records an expenditure.
The getBalance(timestamp: int) -> float method calculates the current balance at a given point in time.
The implementation should exclude expired grants from the balance and ensure transactions are processed in chronological order.
Example
Input
addGrant(100, 1, 5)
addSpend(50, 2)
getBalance(3)