fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  6. #define pb push_back
  7.  
  8. const double PI = 3.141592653589793;
  9.  
  10. int ans = 0;
  11.  
  12. void solve(){
  13. ans = 0;
  14. int n, m;
  15. cin >> n >> m;
  16. int a[n];
  17. int c[n];
  18. vector <int> w;
  19. w.pb(0);
  20. int l[m+1];
  21. for(int i = 0; i <= m; i++)
  22. l[i] = 0;
  23. for(int i = 0; i < n; i++)
  24. cin >> a[i];
  25. for(int i = 0; i < n; i++)
  26. cin >> c[i];
  27. for(int i = 0; i < n; i++){
  28. for(int j = 0; j < c[i]; j++){
  29. vector <int> y;
  30. for(int q = 0; q < w.size(); q++){
  31. if(w[q] + a[i] <= m and l[w[q] + a[i]] == 0){
  32. l[w[q] + a[i]] = 1;
  33. y.pb(w[q] + a[i]);
  34. }
  35. }
  36. for(int q = 0; q < y.size(); q++){
  37. w.pb(y[q]);
  38. }
  39. }
  40.  
  41. }
  42. ans = w.size() - 1;
  43. }
  44. int main() {
  45. fast;
  46. int t;
  47. cin >> t;
  48. for(int i = 0; i < t; i++){
  49. solve();
  50. cout << "Case " << i + 1 << ": " << ans << endl;
  51. }
  52. return 0;
  53. }
Success #stdin #stdout 0s 4392KB
stdin

    2

    3 10

    1 2 4 2 1 1

    2 5

    1 4 2 1
stdout
Case 1: 8
Case 2: 4