#DSU0000097. Các bình chứa nước (Vessels)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các bình chứa nước (Vessels)
Vessels
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are vessels ordered from top to bottom, with capacities liters. Initially all vessels are empty. Water poured into vessel fills it first, then any overflow passes to vessel , and so on. Water overflowing from vessel is lost. Process two operations in order: 1 p x pours liters into vessel ; 2 k asks for the amount of water currently held in vessel . Overflow is fully settled before each query.
Input
The first line contains ; the second contains ; the next line contains ; then follow operations in the formats described above.
Output
For each query of type 2, print the amount of water in the requested vessel on one line.
Subtasks
- Subtask 1 (20 points): , , , , .
- Subtask 2 (30 points): , , , , .
- Subtask 3 (50 points): , , .
Examples
Input
2
5 10
6
1 1 4
2 1
1 2 5
1 1 4
2 1
2 2
Output
4
5
8
Explanation
The first pour leaves liters in vessel . After subsequent operations, vessel contains liters and vessel contains liters.