#include #include #include #include using namespace std; using namespace atcoder; using namespace __gnu_pbds; using ll=long long; using ld=long double; using vll=vector; using vvll=vector; using pll=pair; // using mint=modint; // template // using ordered_map=tree,rb_tree_tag,tree_order_statistics_node_update>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); //合計金額を一つずつチェックすればいい //まずナップサックdpを天ぷらに回す、達成できる金額を記録する //合計金額xのok条件はx-Uはdpから達成できるようなUが存在すること ll N,M; cin>>N>>M; vll U(N),T(M); for(int i=0;i>U[i]; for(int i=0;i>T[i]; ll sumT=0; for(int i=0;idp(sumT+1,false); dp[0]=true; for(auto t:T){ //同じ天ぷらが複数使われないように、後ろから回す for(ll s=sumT;s>=t;--s){ if(dp[s-t])dp[s]=true; } } ll mxU=*max_element(U.begin(),U.end()); vectorok(mxU+sumT+1,false); for(auto u:U){ for(ll s=0;s<=sumT;++s){ if(dp[s])ok[s+u]=true; } } ll ans=0; for(auto x:ok){ if(x)ans++; } cout<