This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int N;
long long M;
long long cost[40];
void smallM(){
	vector<long long int> dp(M+1, 0);
	dp[0] = 1;
	for(int match = 0; match < N; ++match){
		for(long long val = M; val > 0; --val){
			if(cost[match] <= val) dp[val] += dp[val - cost[match]];
		}
	}
	long long ans = 0;
	for(int i = 0; i <= M; ++i) ans += dp[i];
	cout << ans << endl;
}
int main(){
	cin >> N >> M;
	for(int i = 0; i < N; ++i) cin >> cost[i];
	if(N <= 20){
		long long ans = 0;
		for(int mask = 0; mask < (1 << N); ++mask){
			long long sum = 0;
			for(int i = 0; i < N; ++i){
				if(mask & (1 << i))sum+= cost[i];
			}
			if(sum <= M) ans++;
		}
		cout << ans << endl;
	}else{
		smallM();
	}
	return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |