Problem 3059 --Rikka with Traffic Light

3059: Rikka with Traffic Light

"
Time Limit $3$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $0$ 正确数量 $0$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
Rikka is now doing summer intern abroad. Every night, she walks home from school. There is a large crossroad on the shortest path, and in most times, it takes Rikka a long time to wait for the traffic light to turn to green, even though sometimes there are not any cars or pedestrians passing through in the contradict direction. To reduce the waiting time, Rikka wants to help the government reschedule the traffic light.
To make things easier, Rikka does some simplification: Suppose there are n pedestrians, some of them will cross the road vertically and others will cross the road horizontally. The ith pedestrian will arrive at the crossroad after ti seconds.
The traffic light has two possible colors: green and red. The green light means pedestrians can now cross the road vertically while red means crossing the road horizontally is allowed. Initially (i.e., at time 0), the color of the light is green, and the color of the traffic light can be changed at any moment for any times.
For any pedestrian, it will take him/her T1 seconds to cross the road vertically and T2 seconds to cross the road horizontally. Therefore, the ith pedestrian can cross the road at time wi (wi can be a floating number) if and only if wi≥ti and one of the following two conditions is held:
1. The pedestrian wants to cross the road vertically, and at any moment in (wi,wi+T1), the traffic light is green.
2. The pedestrian wants to cross the road horizontally, and at any moment in (wi,wi+T2), the traffic light is red.
Notice that several pedestrians can cross the road at the same time: they will not impact others.
Now, Rikka can schedule the state of the traffic light and the time for each pedestrian to cross the road. She wants to find the optimal valid plan so that the total waiting time is minimized, i.e., ∑ni=1(wi−ti) is minimized. Since ti can be quite large and Rikka does not have enough patience to stay there to control the traffic light, she asks you to help her calculate the answer.

The first line of the input contains a single integer T(1≤T≤200), the number of test cases.

For each test case, the first line contains three positive integers n,T1,T2(1≤n≤3000,1≤T1,T2≤109).

Then n lines follow, each line with two integers ki,ti(ki∈{1,2},1≤ti≤109), which describes the ith pedestrian: The ith pedestrian will arrive at the crossroad after ti seconds, and if ki=1, he/she will cross the road vertically, otherwise he/she will cross the road horizontally.

The input guarantees that there are at most 5 test cases with n>500
For each test case, output a single line with a single integer, the answer.
3
6 1 1
1 1
2 1
1 2
2 2
1 3
2 3
6 1 2
1 1
2 1
1 2
2 2
1 3
2 3
6 1 3
1 1
2 1
1 2
2 2
1 3
2 3
3
5
6
In the first test case, one of the optimal plans is: Set the traffic light to green in time period [0,2]∪[3,4]∪[5,6], and let w={1,2,3,2,3,4}. Therefore the answer is 3.

In the second test case, one of the optimal plans is: Set the traffic light to green in time period [0,3]∪[5,6], and let w={1,3,2,3,5,3}. Therefore the answer is 5.

In the third test case, one of the optimal plans is: Set the traffic light to green in time period [0,4], and let w={1,4,2,4,3,4}. Therefore the answer is 6.

推荐代码 查看3059 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$ $ms]
内存最少[$ $KB]
第一AC
第一挑战

赛题来源/所属竞赛 2019 Multi-University Training Contest 9 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛