Under construction

Still being built. Things may change

Demerit Points

Time limit1sMemory limit128 MB

Summary
Simulate a driver's demerit and merit points over time, applying offense, merit award, and yearly reduction rules, and print each change.
Level

Medium6 of 10

Topics
Simulation, Implementation, Math, Sorting
Solved
No attempts yet

Problem

A certain region manages driver's license demerit points and merit points with the following rules.

A new driver starts with no merit or demerit points. When a driver is convicted of a driving offense, they receive between 2 and 15 demerit points, depending on the severity of the offense.

One merit point is awarded, up to a maximum of five, for each two-year interval in which the driver has no offenses and no demerit points. Each merit point cancels up to two demerit points. When a subsequent offense occurs:

  • If the number of demerit points exceeds double the number of merit points, the demerit points are reduced by double the number of merit points, and the merit points are set to 0.
  • If the number of demerit points is less than or equal to double the number of merit points, the demerit points are reduced to 0, and the merit points are reduced by half the number of demerit points. Any fractional merit points are discarded.

Demerit points are reduced whenever the driver goes one year free of any offense. The reduction lowers the demerit points by half or by 2, whichever is greater. Any fractional or negative demerit points are discarded (set to 0). This reduction takes place on each anniversary of the most recent offense, while demerit points remain.

If a new offense occurs on the same day as a demerit-point reduction or a merit-point award, the reduction/award is applied first, before the new demerit points are added.

Given the records for one driver, output the number of merit or demerit points whenever it changes.

Input

The first line contains the license issue date in yyyymmdd format. Each subsequent line contains offense information in chronological order: the offense date (yyyymmdd) and the demerit points applied (an integer between 2 and 15).

Output

On the license issue date, and whenever the number of merit or demerit points changes, output the date and the points on one line using the format below. Output terminates once merit points reach 5 following the last offense.

  • With demerit points: YYYY-MM-DD N demerit point(s).
  • With merit points: YYYY-MM-DD N merit point(s).
  • With neither: YYYY-MM-DD No merit or demerit points.

Examples1

  1. Example 1

    Input
    19820508
    19830606 2
    19830607 2
    19891212 15
    
    Expected output
    1982-05-08 No merit or demerit points.
    1983-06-06 2 demerit point(s).
    1983-06-07 4 demerit point(s).
    1984-06-07 2 demerit point(s).
    1985-06-07 No merit or demerit points.
    1987-06-07 1 merit point(s).
    1989-06-07 2 merit point(s).
    1989-12-12 11 demerit point(s).
    1990-12-12 5 demerit point(s).
    1991-12-12 2 demerit point(s).
    1992-12-12 No merit or demerit points.
    1994-12-12 1 merit point(s).
    1996-12-12 2 merit point(s).
    1998-12-12 3 merit point(s).
    2000-12-12 4 merit point(s).
    2002-12-12 5 merit point(s).