luogu#P7041. [NWRRC2016] King’s Heir

[NWRRC2016] King’s Heir

题目描述

The king is dead, long live the king! After the sudden death of the king Fert XIII the people of the Flatland Kingdom are going to welcome the new king. Unfortunately, there is a problem, Fert has too many sons.

Actually, he has nn sons and he loved each new son more than all of his previous sons. Well, probably he just stopped loving his sons because of their bad behavior. Anyway, after the new son was born Fert made the new testament that declared that the newly born son would be the heir.

However, there is a problem. Only the king's son who is at least 1818 years old at the moment of the kings deathking's death can become a new king. Now the ministers of the government are trying to find the correct new king,new king, but they seem to fail. Help them!

输入格式

The first line of the input contains three integers: d,md , m and yy -- the day, the month and the year of the king's death, dd is from 11 to 3131 , mm is from 11 to 12,y12 , y is from 11 to 99999999 . It is guaranteed that there exists day dd in month mm , all months have the same number of days in Flatland as in our country, except that Flatland calendar doesn't have leap years, so February (month 22) always has 2828 days.

The second line contains n(1n100)n (1 \le n \le 100) -- the number of king's sons. The following nn lines contain three integers each di,mid_{i}, m_{i} and yi y_{i} and specify the birth dates of king's sons. All dates are correct and no son is born after or on the day of king's death. The king had no twins, so no two sons were born on the same date.

输出格式

Output one integer -- the number of the son that would become the king, or 1−1 if none of them is at least18at least 18 years old. The sons are numbered from 11 to nn in order they are described in the input. The youngest son who is at least 1818 years old at the moment of the king's death would become the king. If theIf the son has his 18th birthday exactly on the day of the king's death, he can become a king.

题目大意

在国王去世的那一天,国王会让年龄最小但已满十八周岁的儿子继承国王,求哪一个儿子继承了国王,若没有儿子满足条件,则输出-1。保证国王不会有双胞胎。

22 10 2016
7
28 2 1999
22 7 1995
21 10 1998
23 10 1998
3 9 2000
1 4 2013
17 12 2004

3

22 10 2016
1
28 2 1999

-1

提示

Time limit: 2 s, Memory limit: 256 MB.