Vacation
InterviewTime limit5sMemory limit64 MB
From a start city on a line with a fixed day budget where each move or city visit costs one day, pick the contiguous block with the most attractions.
- Level
Medium5 of 10
- Topics
- Two pointers, Prefix sum, Array
- Solved
- No attempts yet
Problem
Jianjia is planning a vacation in Taiwan. cities lie along one highway, numbered through . City is adjacent only to and , except the endpoints, which have one neighbor.
City has attractions. Jianjia has vacation days and chooses a starting city before the trip begins. Each day, exactly one of these actions is allowed.
- Move to an adjacent city.
- Visit every attraction in the current city that has not been visited yet.
Attractions in a city are never counted twice. Find the maximum number of distinct attractions Jianjia can visit.
Input
- Line 1: , starting city , and vacation length
- Line 2: through , the attraction counts in order
Output
Print the maximum number of attractions that can be visited.