Prize Coupon
InterviewTime limit1sMemory limit512 MB
Each student has 0 to 3 coupons and may write only their own or an adjacent student's ID; maximize the number of distinct students named on at least one coupon.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Greedy, Array, Implementation
- Solved
- No attempts yet
Problem
There are N students studying at BINUS University numbered from 1 to N. Each student has their own unique identifier (ID).
As a result of recent achievements, BINUS University wants to distribute coupons to their students. The ith student received coupons from the university. For each coupon received, the student must write a student's ID on the back of the coupon. The written ID might belong to the student themselves or another student. However, the university enforces that the ith student cannot write the jth student's ID if the difference between i and j is more than one, i.e. .
After all the students have written a student's ID on the back of each coupon, all coupons are then collected by the university. The university then grants a prize to each student whose ID is written on at least one coupon.
For example, let and .
- The first student can write the second student's ID on two of their coupons, and write the first student's ID on the remaining coupon.
- The third student can write the fourth student's ID on their coupon.
- Therefore, the first, second, and fourth students get at least one prize.
The students want to write the student's ID such that the number of distinct students who get a prize is maximized. The students studying at BINUS University are known to be selfless, so they might not write their own ID and write other's ID instead if it can increase the number of students who will get a prize.
Your task is to determine the maximum number of students who will get a prize.
Input
Input begins with a line containing an integer: () representing the number of students. The next line contains integers: () representing the number of received coupons.
Output
Output in a line an integer representing the maximum number of students who will get a prize.