The bonus salary! Time Limit: 2000 msmemory limit: 65536 kbthis problem will be judged on PKU. Original ID: 3762
64-bit integer Io format: % LLD Java class name: Main
In order to encourage employees 'producti}, ACM company has made a new policy. at the beginning of a period, they give a list of tasks to each employee. in this list, each task is assigned a "Productivity score ". after the firstKDays, the employee who gets the highest score will be awarded bonus salary.
Due to the difficulty of tasks, for taskI-Th:
- It must be done fromHh_li:Mm_li:Ss_liToHh_ri:Mm_ri:Ss_ri.
- This range of time is estimated very strictly so that anyone must use all of this time to finish the task.
Moreover, at a moment, each employee can only do at most one task. And as soon as he finishes a task, he can start doing another one immediately.
Xyy is very hard-working. unfortunately, he's never got the award. thus, he asks you for some optimal strategy. that means, with a given list of tasks, which tasks he shoshould do in the firstKDays to maximize the total productiscore. Notice that one task can be done at most once.
Input
The first line contains 2 integersNAndK(1 ≤N≤ 2000, 0 ≤K≤ 100), indicating the number of tasks and days respectively. This is followedNLines; each line has the following format:
Hh_li:Mm_li:Ss_li Hh_ri:Mm_ri:Ss_ri W
Which means,I-Th task must be done fromHh_li:Mm_li:Ss_liToHh_ri:Mm_ri:Ss_riAnd its productiscore isW. (0 ≤Hh_li,Hh_ri≤ 23, 0 ≤Mm_li,Mm_ri,Ss_li,Ss_ri≤ 59, 1 ≤W≤ 10000). We use exactly 2 digits (possibly with a leading zero) to representHH,MmAndSS. It is guaranteed that the momentHh_ri:Mm_ri:Ss_riIs strictly laterHh_li:Mm_li:Ss_li.
Output
The output only contains a nonnegative integer --- the maximum total productiscore.
Sample Input
5 209:00:00 09:30:00 209:40:00 10:00:00 309:29:00 09:59:00 1009:30:00 23:59:59 407:00:00 09:31:00 3
Sample output
16
Hint
The optimal strategy is:
Day1: task1, Task 4
Day2: Task 3
The total productiscore is 2 + 4 + 10 = 16.
Problem solving: The maximum traffic with minimum cost. Discretization time point.
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 5010; 18 struct arc{ 19 int v,w,f,next; 20 arc(int x = 0,int y = 0,int z = 0,int nxt = 0){ 21 v = x; 22 w = y; 23 f = z; 24 next = nxt; 25 } 26 }; 27 arc e[1000000]; 28 int head[maxn],d[maxn],p[maxn],tot,S,T; 29 bool in[maxn]; 30 int n,m,lisan[maxn<<4],cnt,x[maxn],y[maxn],sc[maxn]; 31 void add(int u,int v,int w,int f){ 32 e[tot] = arc(v,w,f,head[u]); 33 head[u] = tot++; 34 e[tot] = arc(u,-w,0,head[v]); 35 head[v] = tot++; 36 } 37 queue<int>q; 38 bool spfa(){ 39 for(int i = S; i <= T; i++){ 40 d[i] = INF; 41 p[i] = -1; 42 in[i] = false; 43 } 44 while(!q.empty()) q.pop(); 45 d[S] = 0; 46 in[S] = true; 47 q.push(S); 48 while(!q.empty()){ 49 int u = q.front(); 50 q.pop(); 51 in[u] = false; 52 for(int i = head[u]; ~i; i = e[i].next){ 53 if(e[i].f > 0 && d[e[i].v] > d[u] + e[i].w){ 54 d[e[i].v] = d[u] + e[i].w; 55 p[e[i].v] = i; 56 if(!in[e[i].v]){ 57 in[e[i].v] = true; 58 q.push(e[i].v); 59 } 60 } 61 } 62 } 63 return p[T] > -1; 64 } 65 int solve(){ 66 int tmp = 0,minV; 67 while(spfa()){ 68 minV = INF; 69 for(int i = p[T]; ~i; i = p[e[i^1].v]) 70 minV = min(minV,e[i].f); 71 for(int i = p[T]; ~i; i = p[e[i^1].v]){ 72 tmp += minV*e[i].w; 73 e[i].f -= minV; 74 e[i^1].f += minV; 75 } 76 } 77 return tmp; 78 } 79 int main(){ 80 int hh,mm,ss; 81 while(~scanf("%d %d",&n,&m)){ 82 tot = cnt = 0; 83 memset(head,-1,sizeof(head)); 84 for(int i = 0; i < n; i++){ 85 scanf("%d:%d:%d",&hh,&mm,&ss); 86 x[i] = hh*3600 + mm*60 + ss; 87 lisan[cnt++] = x[i]; 88 scanf("%d:%d:%d",&hh,&mm,&ss); 89 y[i] = hh*3600 + mm*60 + ss; 90 lisan[cnt++] = y[i]; 91 scanf("%d",sc+i); 92 } 93 sort(lisan,lisan+cnt); 94 int cnt1 = 1; 95 for(int i = 1; i < cnt; i++) 96 if(lisan[i] != lisan[cnt1-1]) lisan[cnt1++] = lisan[i]; 97 cnt = cnt1; 98 S = 0; 99 T = cnt;100 for(int i = 0; i < cnt; i++) add(i,i+1,0,m);101 for(int i = 0; i < n; i++){102 int tx = lower_bound(lisan,lisan+cnt,x[i]) - lisan;103 int ty = lower_bound(lisan,lisan+cnt,y[i]) - lisan;104 add(tx,ty,-sc[i],1);105 }106 printf("%d\n",-solve());107 }108 return 0;109 }110 /*111 5 2112 09:00:00 09:30:00 2113 09:40:00 10:00:00 3114 09:29:00 09:59:00 10115 09:30:00 23:59:59 4116 07:00:00 09:31:00 3117 */View code
Poj 3762 the bonus salary!