Balance Transaction Rollback

JavaScript Hard 4 views
Back to Questions

Problem Description

First line balance. Next line m. Next m lines are operations: DEBIT x or CREDIT x. If any debit makes balance negative, rollback all and print ROLLBACK and original balance. Else print COMMIT and final balance.

Input Format

Line1: balance. Line2: m. Next m lines ops.

Output Format

Two lines: status and balance.

Sample Test Case

Input:
10 3 DEBIT 3 DEBIT 9 CREDIT 5
Output:
ROLLBACK 10

Constraints

0

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next