优先队列运用 TOJ 4123 Job Scheduling

 

链接:http://acm.tju.edu.cn/toj/showp4123.html
4123.    Job Scheduling

 


Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 130    Accepted Runs: 29


Given N jobs, each denoted by a 2-tuples integer (pi, ri) where pi is the processing time and ri is the release time.
You must construct a schedule for these jobs on a single machine obeying:
(1) at most one job is processed at each point in time;
(2) no job is processed before its release time. Let Ci denote the time at which job i is finished processing, then the goal is to find the schedule that minimizes C1+C2+...+Cn.

INPUT

First line will be a positive integer N (1≤N≤100000) indicating the number of jobs.
Then N lines follow each containing a job (pi, ri), where 0≤pi≤10000 and 0≤ri≤10000.

OUTPUT

The minimum of C1+C2+...+Cn. Please mod the answer by 1e9+7.

Sample Input

 


3
1 0
3 1
1 2

 

Sample Output

 


9


Hint: Time 0: start Job 1. 
Time 1: finish Job 1 and start Job 2.
Time 2: pause Job 2 and start Job 3. 
Time 3: finish Job 3 and start Job 2.
Time 5: finish Job 2.
    C1+C2+C3=1+5+3=9.

 


Source: TJU School Competition 2015

这道题当时想到了最优队列实现但是自己比较搓,不太会实现,当时又卡了另一题所以就没过。

这题的主要思想在每个时间点选择可以开工的工作里所剩完成时间最短的。

 

#include
#include
#include
#include
using namespace std;
#define N 100005
#define MOD 1000000007

struct Job{
	int a,b;
}nodd[N];
int x,ans;
int cmp(Job a1,Job a2){
	if(a1.b==a2.b) return a1.a,greater > q;
        while(i 
 


 

你可能感兴趣的:(优先队列运用 TOJ 4123 Job Scheduling)