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

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


Maximum Sum 2

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

• Edges list to Adjacency matrix
• Permutations
• Reverse permutation
• Divisors count
• GCD of ones
• Set cover problem
• Subsets
• The N Queens Problem
• Maximum Sum 2
• Gifts of Santa Claus
• Shopping
• Diameter of graph
• Corridor
• Prime numbers
• Rectangles on a plane
• Делители

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

Если у вас есть предложения или пожелания по работе 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