HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Unsorted > problem:


Maximum Sum 2

Section problems

• Profits
• Istanbul
• Buying hay
• Sum until 0
• Sum less than N
• Sum of N numbers
• The N Queens Problem
• Subsets
• Maximum Sum 2
• Gifts of Santa Claus
• Rectangles on a plane
• Permutations
• Reverse permutation
• Nameplates
• Adjacency matrix to edges list
• Edges list to Adjacency matrix
• Cities and roads

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 1000/1000/1000/1000 ms. Memory limit 65000/65000/65000/65000 Kb.

Problem description

There is a list of N (1 ≤ N ≤ 20) number of positive integers ni (1 ≤ ni ≤ 100). You should make at most M (1 ≤ M ≤ 5) choices from the list. In each choice you have to take a number of continuous numbers from the list. Each number in the list can be chosen only once and you the choices must be performed in the given order.

What is the maximum sum of the number you can select?

Input

The input consists of three lines. The first line contains two numbers: N and M. The second number contains N numbers that are the numbers in the list. The last number contains M numbers that denote the choices.

Output

The output contains a single integer that is the maximum sum.

Example

stdin stdout

6 2
3 1 5 3 4 2
1 3

15

Для отправки решений необходимо выполнить вход.

www.contester.ru