#CCBOTPBA0000061. Giả lập số dư theo chuỗi lệnh (Simulate an Account Balance)

Giả lập số dư theo chuỗi lệnh (Simulate an Account Balance)

Simulate an Account Balance

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

An account starts with a non-negative integer balance BB. Process nn commands in input order. Each command has an integer code cc and a non-negative integer amount xx. Code 11 deposits xx. Code 22 withdraws xx if the current balance is at least xx; otherwise the withdrawal fails, leaves the balance unchanged, and increases the failure count by one. A zero withdrawal always succeeds. Output the final balance and the number of failed withdrawals.

Input

The first line contains integers BB and nn. Each of the next nn lines contains an integer code cc and amount xx in processing order; cc is either 11 or 22.

Output

Print two integers separated by one space: the final balance and the failed-withdrawal count.

Subtasks

  • Subtask 1 (20%): 0≤B,x≤1000, 0≤n≤200\le B,x\le 1000,\ 0\le n\le 20.
  • Subtask 2 (30%): 0≤B,x≤106, 0≤n≤10000\le B,x\le 10^6,\ 0\le n\le 1000.
  • Subtask 3 (50%): 0≤B,x≤109, 0≤n≤1000000\le B,x\le 10^9,\ 0\le n\le 100000.

Examples

Example 1

Input:

10 5
2 6
2 5
1 7
2 11
2 1

Output:

0 2

Explanation: Start at balance 10 and zero failures. Withdraw 6: balance 4. Withdraw 5: failure 1, balance 4. Deposit 7: balance 11. Withdraw 11: balance 0. Withdraw 1: failure 2, balance 0. Print 0 2.

Example 2

Input:

0 3
2 0
2 1
1 0

Output:

0 1

Explanation: Withdrawing zero at zero balance succeeds. Withdrawing 1 fails, and depositing zero changes nothing. The answer is 0 1.

Example 3

Input:

25 0

Output:

25 0

Explanation: There are no commands. The balance stays 25 and there are zero failures.