Advertisement
Saleh127

UVA 11517

May 23rd, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. test
  11. {
  12.  
  13. ll n,m,i,j,k,l;
  14.  
  15. cin>>n>>m;
  16. ll dp[20000];
  17. ll c[m+4];
  18.  
  19. for(i=0;i<10005;i++) dp[i]=INT_MAX;
  20.  
  21. for(i=0;i<m;i++) cin>>c[i];
  22.  
  23. dp[0]=0;
  24. for(i=0;i<m;i++)
  25. {
  26. for(j=n;j>=0;j--)
  27. {
  28. dp[j+c[i]]=min(dp[j]+1,dp[j+c[i]]);
  29. }
  30. }
  31.  
  32. for(i=n;i<=10000;i++)
  33. {
  34. if(dp[i]<10000)
  35. {
  36. cout<<i<<" "<<dp[i]<<endl;
  37. break;
  38. }
  39. }
  40. }
  41.  
  42. return 0;
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement