#P2949. Farmer John's Job Scheduling
Farmer John's Job Scheduling
Farmer John's Job Scheduling
Farmer John has many jobs to do! With his workday starting at time 0 and lasting for 1,000,000,000 time units, he can only complete a subset of the available jobs. Each job takes exactly one time unit to complete. The i-th job has a deadline \(D_i\) (\(1 \le D_i \le 1,000,000,000\)) and a profit \(P_i\) (\(1 \le P_i \le 1,000,000,000\)). If Farmer John finishes a job by its deadline, he earns the corresponding profit. However, since he can perform at most one job per time unit, it might be impossible to complete all jobs.
Your task is to determine the maximum total profit Farmer John can earn by carefully selecting which jobs to perform.
Note: The answer might not fit into a 32-bit integer.
inputFormat
The first line contains an integer \(N\) (\(1 \le N \le 100,000\)), the number of jobs available. Each of the next \(N\) lines contains two space-separated integers \(D_i\) and \(P_i\), representing the deadline and profit of the i-th job.
outputFormat
Output a single integer representing the maximum total profit Farmer John can earn.
sample
3
1 10
1 5
2 7
17