提交时间:2023-12-02 08:41:49
运行 ID: 113299
#include<iostream> using namespace std; int ary[35], v, n, ans = 1e8; void f(int x, int a){ if(x == n){ ans = min(a, ans); return; } f(x + 1, a); if(a >= ary[x]){ f(x + 1, a - ary[x]); } } int main(){ cin >> v >> n; for(int i = 0; i < n; i++){ cin >> ary[i]; } f(0, v); cout << ans; return 0; }