Orig Description
Score : 400 points
Problem StatementThere are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.
You can take and complete at most one of these jobs in a day.
However, you cannot retake a job that you have already done.
Find the maximum total reward that you can earn no later than M days from today.
You can already start working today.
Constraints
All values in input are integers.
1 \leq N \leq 10^5
1 \leq M \leq 10^5
1 \leq A_i \leq 10^5
1 \leq B_i \leq 10^4
InputInput is given from Standard Input in the following format:
N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N
OutputPrint the maximum total reward that you can earn no later than M days from today.
Sample Input 13 4
4 3
4 1
2 2
Sample Output 15
You can earn the total reward of 5 by taking the jobs as follows:
Take and complete the first job today. You will earn the reward of 3 after four days from today.
Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.
Sample Input 25 3
1 2
1 3
1 4
2 1
2 3
Sample Output 210
Sample Input 31 1
2 1
Sample Output 30
Extracted Specification
An integer N (1 ≤ N ≤ 10^5), representing some quantity or size.
An integer M (1 ≤ M ≤ 10^5), representing some quantity or size.
A list of N tuples, each containing:
- An integer A (1 ≤ A ≤ 10^5)
- An integer B (1 ≤ B ≤ 10^4)
### Example Input:
```
3 4
4 3
4 1
2 2
```
### Function Signature:
Write a function f(inputs) that takes in the input.
def f(inputs: Tuple[int, int, List[Tuple[int, int]]]):
'''
inputs: a tuple containing:
- an integer N
- an integer M
- a list of tuples (A, B)
'''
Test Case Generator
Sure! Let's create a test case generator for the second problem statement. This generator will create random inputs for the problem of finding the maximum total reward for one-off jobs.
Here's the Python code for the test case generator:
```python
import random
def tcgen():
# Generate random values for N and M within given constraints
N = random.randint(1, 100000)
M = random.randint(1, 100000)
# Generate random values for A_i and B_i within given constraints
A = [random.randint(1, 100000) for _ in range(N)]
B = [random.randint(1, 10000) for _ in range(N)]
return N, M, list(zip(A, B))
def format_test_case(N, M, jobs):
# Format the test case as a string
result = f"{N} {M}\n"
for A_i, B_i in jobs:
result += f"{A_i} {B_i}\n"
return result.strip()
# Example usage:
N, M, jobs = tcgen()
test_case = format_test_case(N, M, jobs)
print(test_case)
```
This code will generate a test case with:
1. A random `N` (number of jobs) between 1 and 100000.
2. A random `M` (number of days) between 1 and 100000.
3. A list of `N` pairs `(A_i, B_i)` where:
- `A_i` (days after which the reward is received) is between 1 and 100000.
- `B_i` (reward for the job) is between 1 and 10000.
The function `format_test_case` formats the generated test case into the required input format.
You can run the example usage to see a sample test case output!
Extract Arguments
def extract_arguments(fh):
N, M = map(int, fh.readline().strip().split())
jobs = []
for _ in range(N):
A, B = map(int, fh.readline().strip().split())
jobs.append((A, B))
return N, M, jobs