[USACO 2008 Ope B]Going to the Movies
题号:NC24999
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
64bit IO Format: %lld

题目描述

Farmer John is taking some of his cows to the movies! While his truck has a limited capacity of C (100 <= C <= 5000) kilograms, he wants to take the cows that, in aggregate, weigh as much as possible without exceeding the limit C.
Given N (1 <= N <= 16) cows and their respective weights Wi, determine the weight of the heaviest group of cows that FJ can take to the movies.

输入描述:

* Line 1: Two space-separated integers: C and N
* Lines 2..N+1: Line i+1 contains a single integer: Wi

输出描述:

* Line 1: A single integer that is the weight of the heaviest group of cows that can go to the movies
示例1

输入

复制
259 5
81
58
42
33
61

输出

复制
242

说明

81+58+42+61 = 242; this is the best possible sum