#CCBOTPBA0000035. Chênh lệch thu chi luồng (Final and Minimum Balance)
Chênh lệch thu chi luồng (Final and Minimum Balance)
Final and Minimum Balance
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Start from balance b. Each transaction type 1 adds x and type 2 subtracts x. Output final balance and minimum across the initial and every post-transaction balance; negative balances remain valid.
Input
First n b, followed by n pairs type and amount.
Output
Print final_balance minimum_balance.
Subtasks
-
Subtask 1 (20%):
n ≤ 20, amounts/balance≤100. -
Subtask 2 (30%):
n ≤ 1000, amounts/balance≤10^6. -
Subtask 3 (50%):
n ≤ 100000, amounts/balance≤10^9.
Examples
Example 1
Input:
3 10
1 5
2 20
1 2
Output:
-3 -5
Explanation: Balances are 10,15,-5,-3, hence final -3 and minimum -5.
Example 2
Input:
0 7
Output:
7 7
Explanation: With no transaction both balances equal the initial balance.