Picking Numbers on a Circle
Time limit1sMemory limit512 MB
Pick exactly K numbers from a circle of N values so that no two chosen are adjacent, maximizing the sum.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy, Heap, Linked list
- Solved
- No attempts yet
Problem
kcm1700 gave ntopia the following task. numbers are placed around a circle. Pick of them so that no two picked numbers are neighbors, and make the sum of the picked numbers as large as possible. Picking neighbors means that among the picked numbers there are two that sit next to each other on the circle.
The numbers form a circle, so the first number and the last number are neighbors too. Write a program that computes the largest sum you can get by picking numbers with no two of them adjacent.
Input
The first line contains a positive integer () and an integer (), separated by a space.
The second line contains the natural numbers of the circle in clockwise order, separated by spaces. Each number is smaller than .
Output
Print the maximum sum on the first line. The answer is smaller than .