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 other quantity or size.
A list of \(N\) tuples \((A_i, B_i)\), where \(A_i\) (1 ≤ \(A_i\) ≤ 10^5) and \(B_i\) (1 ≤ \(B_i\) ≤ 10^4) are integers.
### Example Input:
```
3 4
4 3
4 1
2 2
```
### Function Signature:
Write a function `f(N, M, inputs)` that takes in the input.
```python
def f(N: int, M: int, inputs: List[Tuple[int, int]]):
'''
N: an integer
M: an integer
inputs: a list of tuples, where each tuple contains two integers
'''
```
Test Case Generator
Certainly! Here is the test case generator for the given problem statement:
```python
import random
def tcgen():
# Define constraints
N = random.randint(1, 10**5)
M = random.randint(1, 10**5)
A = [random.randint(1, 10**5) for _ in range(N)]
B = [random.randint(1, 10**4) for _ in range(N)]
return N, M, A, B
def generate_test_case():
N, M, A, B = tcgen()
print(f"{N} {M}")
for i in range(N):
print(f"{A[i]} {B[i]}")
# Example of generating and printing a test case
generate_test_case()
```
### Explanation
1. **N**: The number of jobs, randomly chosen between 1 and \(10^5\).
2. **M**: The maximum number of days, randomly chosen between 1 and \(10^5\).
3. **A**: A list of integers representing the days after which the reward will be earned, randomly chosen between 1 and \(10^5\).
4. **B**: A list of integers representing the rewards for each job, randomly chosen between 1 and \(10^4\).
This script generates a random valid test case according to the problem constraints. You can run `generate_test_case()` to print the test case in the required format.
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