Problem p02806 - Generation 3

Orig Description

Score : 200 points
Problem Statement
Niwango created a playlist of N songs.
The title and the duration of the i-th song are s_i and t_i seconds, respectively.
It is guaranteed that s_1,\ldots,s_N are all distinct.
Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.)
However, he fell asleep during his work, and he woke up after all the songs were played.
According to his record, it turned out that he fell asleep at the very end of the song titled X.
Find the duration of time when some song was played while Niwango was asleep.
Constraints
1 \leq N \leq 50
s_i and X are strings of length between 1 and 100 (inclusive) consisting of lowercase English letters.
s_1,\ldots,s_N are distinct.
There exists an integer i such that s_i = X.
1 \leq t_i \leq 1000
t_i is an integer.
Input
Input is given from Standard Input in the following format:
N
s_1 t_1
\vdots
s_{N} t_N
X
Output
Print the answer.
Sample Input 13
dwango 2
sixth 5
prelims 25
dwango
Sample Output 130
While Niwango was asleep, two songs were played: sixth and prelims.
The answer is the total duration of these songs, 30.
Sample Input 21
abcde 1000
abcde
Sample Output 20
No songs were played while Niwango was asleep.
In such a case, the total duration of songs is 0.
Sample Input 315
ypnxn 279
kgjgwx 464
qquhuwq 327
rxing 549
pmuduhznoaqu 832
dagktgdarveusju 595
wunfagppcoi 200
dhavrncwfw 720
jpcmigg 658
wrczqxycivdqn 639
mcmkkbnjfeod 992
htqvkgkbhtytsz 130
twflegsjz 467
dswxxrxuzzfhkp 989
szfwtzfpnscgue 958
pmuduhznoaqu
Sample Output 36348

Extracted Specification

An integer N (1 ≤ N ≤ 50), representing some quantity or size.
A list of tuples, each containing a string of length between 1 and 100 (inclusive) consisting of lowercase English letters, and an integer between 1 and 1000.
A string X of length between 1 and 100 (inclusive) consisting of lowercase English letters.

### Example Input:

```
3
ypnxn 279
kgjgwx 464
qquhuwq 327
qquhuwq
```

### Function Signature:
Write a function f(N, A, X) that takes in the input.
```python
def f(N: int, A: List[Tuple[str, int]], X: str):
    '''
    N: an integer
    A: a list of tuples, where each tuple contains a string and an integer
    X: a string
    '''
```

Test Case Generator

Sure, I can write a test case generator for the given problem statement. Here's the Python code for generating test cases for the problem "Niwango's Playlist":

```python
import random
import string

def generate_song_title():
    length = random.randint(1, 100)
    return ''.join(random.choices(string.ascii_lowercase, k=length))

def tcgen():
    N = random.randint(1, 50)
    
    songs = []
    song_titles = set()
    
    for _ in range(N):
        title = generate_song_title()
        while title in song_titles:
            title = generate_song_title()
        song_titles.add(title)
        
        duration = random.randint(1, 1000)
        songs.append((title, duration))
    
    X = random.choice(songs)[0]
    
    return N, songs, X

# Example of how to use the tcgen function
if __name__ == "__main__":
    N, songs, X = tcgen()
    print(N)
    for title, duration in songs:
        print(f"{title} {duration}")
    print(X)
```

This function `tcgen` will generate:

- A random number of songs `N` (between 1 and 50).
- A list of tuples representing songs, where each tuple contains:
  - A distinct title of length between 1 and 100 characters, comprising lowercase English letters.
  - A duration between 1 and 1000 seconds.
- A song title `X` that is guaranteed to be in the list of songs.

The generated test case can be printed out or used directly in the function to verify outputs. The example at the bottom demonstrates how to print a generated test case in the required format.

To run the generator, you can call `tcgen()` in your testing environment, and it will produce the necessary random test cases for the problem.

Extract Arguments

def extract_arguments(fh):
    N = int(fh.readline().strip())
    songs = []
    for _ in range(N):
        s, t = fh.readline().strip().split()
        t = int(t)
        songs.append((s, t))
    X = fh.readline().strip()
    return N, songs, X