Description

Suppose that N number of stickers are attached in the circle form. The following figure is an example of N = 8.

스티커_hb1jty.jpg

You want to detach some of the stickers in the circle to maximize the sum of numbers written on the detached stickers. But, when detaching a sticker, stickers on both sides are useless because they are damaged.

For example, in the above figure, stickers with number 10 and 6 are useless after detaching sticker with number 14. Numbers written on the stickers are given as an array. Write a function solution to return the maximum sum when detaching stickers. Assume that the first element and the last element are connected to each other, to maintain stickers in the circle form.

Constraints
  • stickers is an array containing the numbers written on stickers attached in the circle form in turn, its length("N") is between 1 and 100,000.
  • Each element of stickers is a number written on each sticker, and it is natural number between 1 and 100.
  • Assume that the first element and the last element are connected each other, to maintain stickers in the circle form.

Examples
sticker answer
[14, 6, 5, 11, 3, 9, 2, 10] 36
[1, 3, 2, 5, 4] 8

Example #1
The sum of numbers is maximized as 36 when detaching stickers with 6, 11, 9, and 10.

Example #2
The sum of numbers is maximized as 8 when detaching stickers with 3, and 5.

Result Stop
내가 제출한 코드가 왜 틀렸는지 프로그래머스 AI에게 물어보세요.
제출 후 채점하기를 눌러 30점 이상인 경우 물어볼 수 있어요.
베타 기간 동안에는 한 문제당 1번만 물어볼 수 있어요.