PROBLEM STATEMENT
Under the current New Jersey point system, all points for traffic violations
committed on or after March 1, 1974 are included in the overall point total.
The point total is reduced at the rate of three points for each one year period
in which the licensee has not committed a violation, but no point total is
reduced below zero.
Your task is, given a String[] of dates of violations and a corresponding int[]
of points awarded, return the total points on a given date represented by the
String currentDate.
NOTES
1. Dates are in order.
2. Dates are not necessarily distinct.
3. To simplify things, ignore leap days. Assume that every year has 365 days
and never has a leap day (02/29).
4. If there is a violation on the current date, its points should be included
in the answer.
5. If the last violation occurred on some day of year M, then the point
reduction doesn't appear on the same day of year M+1; the point reduction
appears on the next day. For example:
- last violation 09/10/91; current date 09/10/92: there is no point reduction
- last violation 09/10/91; current date 09/11/92: there is a point reduction
- violation 09/10/91, next violation 09/10/92, current date 09/11/92: there is
no point reduction
DEFINITION
Class: Speeding
Method: points
Parameters: String[], String int[]
Returns: int
Method signature (be sure your method is public): int points(String[] dates,
String currentDate, int[] points);
TopCoder will ensure the validity of the inputs. Inputs are valid if all of the
following criteria are met:
- dates will have between 0 and 10 elements inclusive
- each element of dates and the currentDate will represent a real date between
March 1, 1974 and June 26, 2002, inclusive
- no element of dates or currentDate will be February 29th of a leap year
- each element of dates and the currentDate will be a date in the format
"mm/dd/yy", where month (mm), day (dd) and year (yy) will be represented by
exactly two digits adding leading zeros when necessary. There will be no
leading or trailing spaces. For example, "03/02/01" represents March 2, 2001
and "12/31/99" represents December 31, 1999
- points will have the same number of elements as dates
- each point will be between 1 and 8 inclusive
- dates will be sorted in chronologically ascending order
EXAMPLES
1. dates = {"01/08/00","01/08/01"} currentDate = "01/08/02" points = {4,4},
return 8
2. dates = {"01/08/00","01/09/01"} currentDate = "01/08/02" points = {2,2}, on
01/09/01 there is a point reduction for the first violation, it reduces the
point total by 3, but it can't reduce the point total below zero, hence the
reduction is by 2 points, making it equal to 0. On 01/09/01 the new violation
occurs, return 2
3. dates = {"01/08/00","02/08/01","03/08/01"} currentDate = "03/08/02" points =
{2,4,2}, return 6
4. dates = {"01/08/00","01/08/01"} currentDate = "03/08/00" points = {4,4},
return 4
5. dates = {"01/08/00","01/08/01"} currentDate = "01/08/99" points = {4,4},
return 0
6. dates = ("10/09/91"} currentDate = "01/08/94" points = {8}, return 2
7. dates = {"09/10/91"} currentDate = "09/10/91" points = {6}, return 6
8. dates = {"01/01/90"} currentDate = "01/01/92" points = {8}, return 5
9. dates = {"01/01/95","01/01/99"} currentDate = "01/02/99" points = {5,5},
return 5