Optimizing the Matrix
InterviewTime limit1sMemory limit1024 MB
Pick one node and spread its action k nodes in each direction, zeroing the reached nodes and multiplying the chosen one. Find the maximum total importance.
- Level
Easy3 of 10
- Topics
- Prefix sum, Implementation
- Solved
- No attempts yet
Problem
The AI that keeps the Matrix running is a complex system, so the Architect decided to try optimizing it.
The system can be modeled as nodes connected in a sequence. Each node has a special characteristic , its computational importance.
The Architect picks one node and spreads its action to neighboring nodes in each direction. If a direction has fewer than nodes, the action spreads to all of them. Let be the total number of nodes the action reaches. Then the computational importance of the chosen node becomes , and the nodes reached by the action get importance .
Help the Architect find the maximum total computational importance of the system that can be obtained by performing this action.
Input
The first line contains two integers and , the number of computational nodes and the number of nodes the action spreads to in one direction (; ).
The second line contains positive integers separated by spaces, the computational importance of each node ().
Output
Print one integer, the maximum total computational importance of the system that can be obtained.