fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n, s, d, a[1010], t[1010], f[1010][110][2];
  4.  
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(NULL);
  9. cout.tie(NULL);
  10.  
  11. // freopen("VD1.INP", "r", stdin);
  12. // freopen("VD1.OUT", "w", stdout);
  13.  
  14. cin >> n >> s >> d;
  15. for (int i = 1; i <= n; i++)
  16. cin >> a[i];
  17. for (int i = 1; i <= n; i++)
  18. cin >> t[i];
  19.  
  20. for (int i = 1; i <= n; i++)
  21. for (int j = 1; j <= s; j++)
  22. {
  23. f[i][j][0] = max(f[i - 1][j][0], f[i - 1][j][1]);
  24. for (int k = max(0, i - d); k < i; k++)
  25. if (j >= t[i])
  26. f[i][j][1] = max(f[i][j][1], f[k][j - t[i]][1] + a[i]);
  27. }
  28.  
  29. cout << max(f[n][s][0], f[n][s][1]);
  30.  
  31. return 0;
  32. }
  33.  
  34. ///******************20210080******************///
Success #stdin #stdout 0s 5280KB
stdin
6 6 2
6 8 5 10 11 6
1 2 2 3 3 2
stdout
24