Citizenship

면접 대비

시간 제한4초메모리 제한1024 MB

요약
출국 기록이 주어질 때, 마지막 출국일 이후로 각 1년 구간마다 최소 d일 이상 체류한 가장 이른 신청 가능 날짜를 구한다.
난이도

보통10점 중 6점

유형
투 포인터, 슬라이딩 윈도우, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

It has been a long time since you moved to a different country and you have decided it is time to become a citizen. Your new country has a strict residency requirement for all applicants. To apply, you must have been physically present in the country for at least dd days per year, for the past yy consecutive years. These years are counted in 1212-month periods backwards from the application date.

For this problem, assume that a calendar year has 1212 months of 365365 days, and each month has exactly the number of days below:

month010203040506070809101112
days312831303130313130313031

For example, if you were to apply on 2024–09–19 you must have been in the country for at least dd days during the 1212-month periods from 2023–09–19 to 2024–09–18, 2022–09–19 to 2023–09–18, and so on for yy such periods.

You have lived in the country for at least yy years, but having traveled a lot, you are not sure if you meet the residency requirement. Write a program that finds the earliest date you can submit your citizenship application given your travel history.

입력

The first line contains three integers nn, yy and dd (1≤n≤5001 ≤ n ≤ 500, 1≤y≤1,0001 ≤ y ≤ 1\\, 000, 1≤d≤3651 ≤ d ≤ 365). You have been out of the country nn times and yy and dd specify the country’s residency requirement as described above.

Each of the following n lines contains two dates in the form YYYY-MM-DD (0000≤0000 ≤ YYYY≤5,000 ≤ 5\\, 000, 01≤01 ≤ MM≤12 ≤ 12, 01≤01 ≤ DD≤31 ≤ 31). You have been out of the country between the two dates, inclusive. All dates in the input are sorted in increasing order. The only dates which may be equal are dates on the same line. All given dates are valid.

출력

Output the earliest date on which you meet the residency requirement. The date must be after the last date of the input.

예제2

  1. 예제 1

    입력
    3 5 240
    2022-02-28 2022-10-01
    2022-11-11 2022-11-11
    2023-12-30 2024-01-01
    
    예상 출력
    2024-05-31
    
  2. 예제 2

    입력
    3 5 240
    2011-11-11 2012-12-12
    2022-02-28 2022-10-01
    2025-01-01 2025-06-30
    
    예상 출력
    2028-02-26