Programming contests

DEIK Regionális Programozó Csapatverseny, nyílt kategória, 2017. december 3.

December 3, 2017 10:10 AM – December 3, 2017 3:10 PM

J — Assigning Workstations


Picture by NASA

Penelope is part of the admin team of the newly built supercomputer. Her job is to assign workstations to the researchers who come here to run their computations at the supercomputer.

Penelope is very lazy and hates unlocking machines for the arriving researchers. She can unlock the machines remotely from her desk but does not feel that this menial task matches her qualifications. Should she decide to ignore the security guidelines, she could simply ask the researchers not to lock their workstations when they leave and then assign new researchers to workstations that are not used anymore but that are still unlocked. That way, she only needs to unlock each workstation for the first researcher using it, which would be a huge improvement for Penelope.

Unfortunately, unused workstations lock themselves automatically if they are unused for more than m minutes. After a workstation has locked itself, Penelope has to unlock it again for the next researcher using it. Given the exact schedule of arriving and leaving researchers, can you tell Penelope how many unlockings she may save by asking the researchers not to lock their workstations when they leave and assigning arriving researchers to workstations in an optimal way? You may assume that there are always enough workstations available.

Input Specification

The input consists of:

  • one line with two integers n (1 ≤ n ≤ 300 000), the number of researchers, and m (1 ≤ m ≤ 108), the number of minutes of inactivity after which a workstation locks itself;
  • n lines, each with two integers a and s (1 ≤ as ≤ 108), representing a researcher who arrives after a minutes and stays for exactly s minutes.

Output Specification

Output the maximum number of unlockings Penelope may save herself.

Sample Input 1

  1. 3 5
  2. 1 5
  3. 6 3
  4. 14 6
download as text file

Output for Sample Input 1

  1. 2
download as text file

Sample Input 2

  1. 5 10
  2. 2 6
  3. 1 2
  4. 17 7
  5. 3 9
  6. 15 6
download as text file

Output for Sample Input 2

  1. 3
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019