QOJ.ac

QOJ

Time Limit: 0.5 s Memory Limit: 32 MB Total points: 100

#11054. Postering

Statistics

All the buildings in the east district of Byteburg were built in accordance with the old arbitecture: they stand next to each other with no spacing inbetween. Together they form a very long chain of buildings of diverse height, extending from east to west.

The mayor of Byteburg, Byteasar, has decided to have the north face of the chain covered with posters. Byteasar ponders over the minimum number of posters sufficient to cover the whole north face. The posters have rectangular shape with vertical and horizontal sides. They cannot overlap, but may touch each other, i.e. have common points on the sides. Every poster has to entirely adjoin the walls of certain buildings and the whole surface of the north face has to be covered.

Write a programme that:

  • reads the description of buildings from the standard input,
  • determines the minimum number of posters needed to entirely cover their north faces,
  • writes out the outcome to the standard output.

Input

The first line of the standard input contains one integer $n$ ($1 ≤ n ≤ 250\,000$), denoting the number of buildings the chain comprises of. Each of the following $n$ lines contains two integers $d_i$ and $w_i$ ($1 ≤ d_i,w_i ≤ 1\,000\,000\,000$), separated by a single space, denoting respectively the length and height of the ith building in the row.

Output

The first and only line of the standard output should contain one integer, the minimum number of rectangular posters that suffice to cover the north faces of the buildings.

Example

Input

5
1 2
1 3
2 2
2 5
1 4
problem_11054_1.gif

Output

4
problem_11054_2.gif

The figures show the north face of the buildings chain. The second figure shows an exemplary covering of the face with four posters.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.