Submit | All submissions | Best solutions | Back to list |
EIUCOINS2 - Maximum Sum of Non-Adjacent Coins |
You are given N coins arranged in a row. Each coin has a positive value. Select a subset of coins to maximize the total value, with the constraint that no two selected coins can be adjacent.
Input
- First line: integer N (1 ≤ N ≤ 106)
- Second line: N positive integers vi (1 ≤ vi ≤ 106)
Output
- First line: Maximum total value
- Second line: Indices of selected coins in any order (1-indexed)
Example
Input:
4
5 1 3 2
Output:
8
1 3
Added by: | Ha Minh Ngoc |
Date: | 2025-08-30 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG FSHARP GO JAVA JS-MONKEY NODEJS PHP PYTHON PYPY PYPY3 PYTHON3 RUBY SQLITE SWIFT VB.NET |