Passport Stamps
InterviewTime limit1sMemory limit2048 MB
Given trips that each need c contiguous blank pages, find the first trip an adversarial officer could block in a passport of p pages.
Problem
You just got your new passport, with fresh pages ready to be stamped by immigration officers. Sadly, your passport has so many pages that the officers are too lazy to use them efficiently, so you may need a new passport sooner than you think.
You have some trips planned. For each trip, when you go through passport control, the immigration officer looks for some contiguous pages, none of which are stamped, and stamps all of them. Because the officer is lazy, there is no guarantee which contiguous pages get stamped.
You make these trips in order until your passport no longer has enough contiguous empty pages for the next trip, at which point you apply for a new passport. Your plans are fixed. You will not skip a trip in the middle, even if skipping it would let you make more future trips.
If the immigration officers conspire against you, find the first trip where it is possible that you cannot travel because your passport does not have enough consecutive blank pages. If you can always make all trips without running out of blank pages, report that instead.
Input
The first line contains two integers () and (), where is the number of planned trips and is the number of pages in your new passport.
Each of the next lines contains a single integer (), the number of contiguous pages that need to be stamped for that trip.
Output
Output a single integer: the minimum number of trips you could take before you need a new passport because there are not enough consecutive blank pages for your next trip. Output if you can take all trips, even in the worst case.