Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- typedef pair<ll, ll> pii;
- typedef pair<ld, ld> pdd;
- int arr[10005];
- int res[10000005];
- int main()
- {
- //freopen("input.txt","r",stdin);
- //freopen("output.txt","w",stdout);
- //ios_base::sync_with_stdio(0);
- int n, sum;
- cin >> n >> sum;
- for(int i=0; i<n; ++i)
- {
- cin >> arr[i];
- }
- for(int i=0; i<n; ++i)
- {
- for(int j=sum; j>0; --j)
- {
- if(res[j])
- {
- if(res[j+arr[i]])
- {
- res[j+arr[i]] = min(res[j+arr[i]], 1+res[j]);
- }
- else
- {
- res[j+arr[i]] = res[j] + 1;
- }
- }
- }
- res[arr[i]]=1;
- }
- cout << res[sum];
- //system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment