Orig Description
Problem B: Old Bridges
Long long ago, there was a thief. Looking for treasures, he was running about all over the world. One day, he heard a rumor that there were islands that had large amount of treasures, so he decided to head for there.
Finally he found n islands that had treasures and one island that had nothing. Most of islands had seashore and he can land only on an island which had nothing. He walked around the island and found that there was an old bridge between this island and each of all other n islands.
He tries to visit all islands one by one and pick all the treasures up. Since he is afraid to be stolen, he visits with bringing all treasures that he has picked up. He is a strong man and can bring all the treasures at a time, but the old bridges will break if he cross it with taking certain or more amount of treasures.
Please write a program that judges if he can collect all the treasures and can be back to the island where he land on by properly selecting an order of his visit.
Input
Input consists of several datasets.
The first line of each dataset contains an integer n.
Next n lines represents information of the islands. Each line has two integers, which means the amount of treasures of the island and the maximal amount that he can take when he crosses the bridge to the islands, respectively.
The end of input is represented by a case with n = 0.
Output
For each dataset, if he can collect all the treasures and can be back, print "Yes" Otherwise print "No"
Constraints
1 ≤ n ≤ 25
Sample Input
3
2 3
3 6
1 2
3
2 3
3 5
1 2
0
Output for the Sample Input
Yes
No
Extracted Specification
Canonicalized Input Description:
An integer n (0 ≤ n ≤ 25), representing some quantity or size.
Next n lines each contain two integers: the first integer is between 0 and 10^6, the second integer is between 0 and 10^6.
The sequence of datasets ends with a case where n = 0.
### Example Input:
```
3
2 3
3 6
1 2
3
2 3
3 5
1 2
0
```
### Function Signature:
Write a function f(inputs) that takes in the input.
def f(inputs: List[Tuple[int, List[Tuple[int, int]]]]):
'''
inputs: a list of tuples
'''
Test Case Generator
Sure! Below is a test case generator for the problem statement "Old Bridges" described above:
```python
import random
def tcgen():
datasets = []
while True:
# Generate a random number of islands n
n = random.randint(1, 25)
# Generate the treasures and bridge limits for each island
islands_info = []
for _ in range(n):
treasure = random.randint(1, 50) # Assuming treasure amount can be between 1 and 50 for variability
max_bridge_load = random.randint(treasure, 100) # Ensuring max_bridge_load >= treasure for feasibility
islands_info.append((treasure, max_bridge_load))
# Add the dataset to the list
datasets.append((n, islands_info))
# Break loop randomly to simulate multiple datasets, ensuring there is at least one dataset
if random.choice([True, False]) and len(datasets) > 1:
break
# Add the terminating dataset (n=0)
datasets.append((0, []))
return datasets
# Example usage
if __name__ == "__main__":
datasets = tcgen()
for dataset in datasets:
n, islands_info = dataset
if n == 0:
print(n)
else:
print(n)
for treasure, max_bridge_load in islands_info:
print(treasure, max_bridge_load)
```
### Explanation
1. **Random Dataset Generation**:
- A random number of islands `n` (1 ≤ `n` ≤ 25) is generated.
- For each island, a random amount of treasures and a maximum bridge load are generated. The maximum bridge load is ensured to be at least as large as the treasure amount to have valid test cases.
2. **Multiple Datasets**:
- Multiple datasets are generated until a random choice decides to stop, ensuring there is at least one valid dataset.
3. **Terminating Dataset**:
- Finally, a terminating dataset with `n = 0` is added to signify the end of input.
4. **Output Format**:
- The generated datasets are printed in the specified format.
This test case generator ensures a variety of input scenarios which can be used to thoroughly test the solution for the "Old Bridges" problem.
Extract Arguments
def extract_arguments(fh):
datasets = []
while True:
n = int(fh.readline().strip())
if n == 0:
break
islands = []
for _ in range(n):
treasures, max_weight = map(int, fh.readline().strip().split())
islands.append((treasures, max_weight))
datasets.append(islands)
return datasets
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# datasets = extract_arguments(fh)
# for dataset in datasets:
# f(dataset)