This page is still under construction.

Parts of this page are still being built. What you see may change.

Boxes on a Shelf

Time limit2sMemory limit512 MB

Summary
Choose which boxes to place on a shelf of length L so that each box's center lies strictly inside the shelf, maximizing the count.
Level

Medium6 of 10

Topics
Greedy, Sorting, Math, Two pointers
Solved
No attempts yet

Problem

Varya has a barn where she stores nn boxes with important stuff. She recently nailed another shelf to the barn wall. Now she wants to put as many boxes as possible on the new shelf.

We shall look at the wall with the shelf as a plane. The shelf is then a horizontal segment of length LL. There is empty space to the left and to the right of the shelf, which we can consider to be infinite. Box number ii is a rectangle with sides a_ia\_i and b_ib\_i.

A box can stand on the shelf and not fall when one of its sides, or a part of it, lies on the shelf, and the center of the box is above an interior point of the shelf. Boxes can be placed only on the shelf, close to the wall: they can not be placed on top of other boxes or in several layers.

Find is the maximum number of boxes Varya can put on the shelf.

Input

The first line contains an integer nn: the number of boxes (1≤n≤100 0001 \le n \le 100\,000). Each of the following nn lines contains two integers a_ia\_i and b_ib\_i: the sides of the respective box (1≤a_i,b_i≤100 0001 \le a\_i, b\_i \le 100\,000). The last line contains an integer LL: the length of the shelf (1≤L≤1091 \le L \le 10^9).

Output

Print one integer: the maximum number of boxes Varya can put on the shelf so that they don't fall off.

Notes

In the first example, Varya can place three boxes on the shelf: for example, the second box lying on side of length 44 on the left, the fourth box lying on side of length 22 at the center, and the first box lying on side 33 on the right.

In the second example, if all three boxes are placed on the shelf symmetrically, they will fall off, as the centers of left and right boxes will be located exactly above the ends of the shelf.

Examples2

  1. Example 1

    Input
    4
    3 5
    6 4
    10 20
    2 2
    7
    
    Expected output
    3
    
  2. Example 2

    Input
    3
    1 1
    1 1
    1 1
    2
    
    Expected output
    2