ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Сборники > Camp. Turkey > задача:


Maximum Sum 2

Задачи сборника

• A Palace with Many Columns
• A+B
• Herons
• City Tour
• Workshop
• 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

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 1000/1000/1000/1000 мс. Лимит памяти 65000/65000/65000/65000 Кб.

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