Test instructions is a time for you to milk a worker and then let you find the longest continuous working time and the longest continuous non-working time. After discretization, you can simply sweep it once:
/*id:m1500293 lang:c++ prog:milk2*/#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;intN;intx[2* the+ -];intnum;structperson{intx, y; BOOL operator< (ConstPERSON&R)Const { returnX <r.x; }}; Person per[ the+Ten];BOOLJudgeintX1,intx2) { for(intI=0; i<n; i++) { if(Per[i].x<=x1 && per[i].y>=x2)return true; } return false;}intMain () {Freopen ("milk2.in","R", stdin); Freopen ("Milk2.out","W", stdout); while(SCANF ("%d", &n) = =1) {num=0; for(intI=0; i<n; i++) { intx1, x2; scanf ("%d%d", &x1, &x2); per[i].x=x1; per[i].y=x2; X[num++] =X1; X[num++] =x2; } sort (x, x+num); Num= Unique (x, X+num)-x; Sort (per, per+N); intmaxwk=0, maxfe=0; inttpwk=0, tpfe=0; for(intI=0; i<num-1; i++) { if(Judge (X[i], x[i+1]))//belongs to working hours{tpwk+ = x[i+1] -X[i]; Maxfe=Max (Maxfe, TPFE); TPFE=0; } Else{TPFE+ = x[i+1] -X[i]; Maxwk=Max (MAXWK, TPWK); Tpwk=0; }} Maxfe=Max (Maxfe, TPFE); Maxwk=Max (MAXWK, TPWK); printf ("%d%d\n", Maxwk, Maxfe); } return 0;}
Usaco Milking Cows