CF721E.Road to Home

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Once Danil the student was returning home from tram stop lately by straight road of length LL . The stop is located at the point x=0x=0 , but the Danil's home — at the point x=Lx=L . Danil goes from x=0x=0 to x=Lx=L with a constant speed and does not change direction of movement.

There are nn street lights at the road, each of which lights some continuous segment of the road. All of the nn lightened segments do not share common points.

Danil loves to sing, thus he wants to sing his favourite song over and over again during his walk. As soon as non-lightened segments of the road scare him, he sings only when he goes through the lightened segments.

Danil passes distance pp while performing his favourite song once. Danil can't start another performance if the segment passed while performing is not fully lightened. Moreover, if Danil has taken a pause between two performances, he is not performing while not having passed a segment of length at least tt . Formally,

  1. Danil can start single performance at a point xx only if every point of segment [x,x+p][x,x+p] is lightened;
  2. If Danil has finished performing at a point x+px+p , then the next performance can be started only at a point yy such that y=x+py=x+p or y>=x+p+ty>=x+p+t satisfying the statement under the point 11 .

Blue half-circles denote performances. Please note that just after Danil has taken a pause in performing, he has not sang for a path of length of at least tt .Determine how many times Danil can perform his favourite song during his walk from x=0x=0 to x=Lx=L .

Please note that Danil does not break a single performance, thus, started singing another time, he finishes singing when having a segment of length of pp passed from the performance start point.

输入格式

The first line of the input contains four integers LL , nn , pp and tt ( 1<=L<=1091<=L<=10^{9} , 0<=n<=1000000<=n<=100000 , 1<=p<=1091<=p<=10^{9} , 1<=t<=1091<=t<=10^{9} ) — the length of the Danil's path, the number of street lights at the road, the distance Danil passes while doing single performance and the minimum distance of pause respectively.

The next nn lines describe segments lightened by street lights. ii -th of them contains two integers li,ril_{i},r_{i} ( 0<=l_{i}<r_{i}<=L ) — the endpoints of the segment lightened by ii -th street light. It is guaranteed that no two segments are intersecting, nesting, or touching each other. The segments are given in the order from left to right.

输出格式

Print the only integer — the maximum number of performances of Danil's favourite song on the path from x=0x=0 to x=Lx=L .

输入输出样例

  • 输入#1

    17 2 2 6
    0 9
    13 17
    

    输出#1

    5
    
  • 输入#2

    12 2 2 2
    0 5
    6 11
    

    输出#2

    4
    
  • 输入#3

    12 2 2 4
    0 5
    6 11
    

    输出#3

    3
    

说明/提示

The first sample case is just about corresponding to the picture from the statement.

首页