No.258 Conveyor Belt Sushi (2)
タグ : / 解いたユーザー数 205
作問者 :
Problem Statement
You are at a conveyor belt sushi restaurant.
N plates of sushi come along the belt in order. The deliciousness of each of the N plates of sushi is represented by \(V_i\).
You can take a plate of sushi when it comes in front of you, but under this restaurant's rules,
you cannot take plates consecutively.
Of course, you also cannot take sushi that has already passed in front of you.
Find the maximum total deliciousness you can obtain and the numbers of the plates you took (numbered starting from 1) in ascending order.
The sushi does not come around a second time.
Input
\(N \) \(V_1\,V_2\,V_3 \ldots V_N \)
The first line contains the number of sushi plates \(N (1\le N \le 1000)\).
The second line contains the deliciousness of the $i$-th sushi \( V_i (1\le V_i \le 100,1 \le i \le N) \), separated by single spaces.
Output
Output the maximum total deliciousness you can obtain on the first line, and
the numbers of the plates you took (1-indexed), separated by spaces, on the second line.
If there are multiple answers, output any one of them.
If there is no answer at all, you may eat whatever sushi you like.
Sample
Sample 1
Input
4 1 2 3 4
Output
6 2 4
The ways to take sushi include taking the "1st and 3rd" sushi, taking the "1st and 4th" sushi, or taking the "2nd and 4th" sushi,
and taking the 2nd and 4th sushi gives the maximum deliciousness.
Sample 2
Input
4 5 4 4 9
Output
14 1 4
Taking the 1st sushi and the 4th sushi gives the maximum total deliciousness.
Sample 3
Input
7 1 2 9 10 1 1 4
Output
16 2 4 7
Taking 2, 10, 4 gives the maximum of 16.
You must deliberately skip the 1 at position 6 after the 10.
Sample 4
Input
1 100
Output
100 1
There may be only one plate.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。