fork download
  1. /*
  2. Task: 1415C
  3. Date: Dec 28, 2020
  4. Author: frostbyte2103
  5. */
  6.  
  7. #include<bits/stdc++.h>
  8. const int inf = 1e9;
  9. using namespace std;
  10.  
  11. void Solve()
  12. {
  13. int n, p, k; cin >> n >> p >> k;
  14. string s; cin >> s;
  15. s = ' ' + s;
  16. int x, y; cin >> x >> y;
  17. vector<int> dp(n + 1, inf); dp[0] = 0;
  18. for (int i=p; i<=n; i++)
  19. {
  20. dp[i] = min(dp[i], (i - p) * y + (s[i]=='1' ? 0 : x));
  21. if (i>k) dp[i] = min(dp[i], dp[i - k] + (s[i]=='1' ? 0 : x));
  22. }
  23. int res = inf;
  24. for (int i=n; i>=n-k+1; i--) res = min(res, dp[i]);
  25. cout << res << '\n';
  26. }
  27.  
  28. int main()
  29. {
  30. ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  31. //freopen("input.txt","r",stdin);
  32. int nTest; cin >> nTest;
  33. while (nTest--) Solve();
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5420KB
stdin
3
10 3 2
0101010101
2 2
5 4 1
00000
2 10
11 2 3
10110011000
4 3
stdout
2
4
10