Skip to main content

Algorithms · Greedy algorithms and exchange proofs

The n vertices of a cycle are numbered 1,…,n, and vertex i has an integer weight

Problem

The \(n\) vertices of a cycle are numbered \(1,\ldots,n\), and vertex \(i\) has an integer weight. Choose exactly \(k\) vertices with no adjacent pair, where vertices \(1,n\) are adjacent. Maximize total weight and output the maximum and selected vertex numbers in increasing order. Any optimum may be output. The input satisfies \[ 2\le n\le200{,}000,\quad 0\le k\le\lfloor n/2\rfloor,\quad n\max(1,k)\le20{,}000{,}000, \] and every weight lies in \([-10^9,10^9]\).

Hint

Split according to whether vertex \(1\) is selected.

Check your work

Work the problem yourself first. Then open it in Training to check your answer and read the full worked solution.

The answer check and full solution for this problem come with ProofAnvil Practice membership ($19 USD monthly). See membership. Or start with the free Algorithms sample problem: Try the free sample problem.

More Algorithms practice problems

Back to Algorithms

An original ProofAnvil practice problem, written for this course. ProofAnvil is a practice course, not a homework-answer service.