#include using namespace std; #define _p(...) (void)printf(__VA_ARGS__) #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define ALL(x) (x).begin(), (x).end() #define BIT(n) (1LL<<(n)) #define SZ(x) ((int)(x).size()) #define fst first #define snd second typedef vector vi;typedef vector vvi;typedef pair pii;typedef vector vpii; typedef long long ll; template inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } int solve(int N1, int N2, int M, vi &A) { vvi dp(M+1, vi(N1+1, -1)); dp[0][0] = 0; rep(i, M) rep(j, N1+1) if (dp[i][j] >= 0) { dp[i+1][j] = dp[i][j]; if (j + A[i] <= N1) amax(dp[i+1][j + A[i]], dp[i][j] + 1); } /* rep(i,M+1) { _p("dp[%d]:", i); rep(j,SZ(dp[i])) _p(" %d", dp[i][j]); _p("\n"); } */ int ma = 0; rep(i, N1+1) { if (dp[M][i] >= dp[M][ma]) { ma = i; } } //cout<<"ma: "< used; rrep(i, 1, M+1) { if (ma - A[i-1] >= 0 && dp[i][ma] == dp[i-1][ma - A[i-1]] + 1) { used.insert(i-1); ma -= A[i-1]; } } //forr(u, used) _p("u: %d\n", u); vi dp2(N2+1, -1); dp2[0] = 0; rep(i, M) if (used.count(i) == 0) rrep(j, N2) if (dp2[j] >= 0) { if (j + A[i] <= N2) amax(dp2[j + A[i]], dp2[j] + 1); } //rep(i,SZ(dp2)) cout<<"dp2["<