#K37197. Unique Sequence Integers

    ID: 25923 Type: Default 1000ms 256MiB

Unique Sequence Integers

Unique Sequence Integers

Alice is a computer science student who loves algorithm challenges. In this problem, you are given T test cases. For each test case, you first receive an integer N representing the number of pairs. Then, you are provided with N pairs in the format (ai, bi). For each pair, you must add the integer ai to a sequence S exactly bi times. Finally, your task is to determine the number of unique integers present in the sequence S.

The underlying operation can be mathematically described as follows:

For each test case, given pairs \((a_i, b_i)\) for \(i=1\) to \(N\), form the sequence \[ S = \underbrace{\{\overbrace{a_1, a_1, \dots, a_1}^{b_1 \text{ times}}\}}_{\text{from pair }1} \cup \underbrace{\{\overbrace{a_2, a_2, \dots, a_2}^{b_2 \text{ times}}\}}_{\text{from pair }2} \cup \cdots \cup \underbrace{\{\overbrace{a_N, a_N, \dots, a_N}^{b_N \text{ times}}\}}_{\text{from pair }N}. \] Then, compute \(|\{ x : x \in S \}|\), i.e. the number of unique integers in \(S\).

inputFormat

The input is read from standard input (stdin). The first line contains an integer T denoting the number of test cases. For each test case, the first line contains an integer N — the number of pairs. This is followed by N lines, each containing two space-separated integers a and b.

outputFormat

For each test case, output a single integer on a new line representing the number of unique integers in the generated sequence S.## sample

1
1
1 5
1