fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define N int(1e3)
  4. using namespace std;
  5. ll n;
  6. string s, t;
  7. ll a[N+10], b[N+10];
  8. ll dp[N+10][N+10];
  9. bool kt(ll i,ll j)
  10. {
  11. return ((s[i-1] == 'W' && t[j-1] == 'L' && a[i-1] > b[j-1]) ||(s[i-1] == 'L' && t[j-1] == 'W' && a[i-1] < b[j-1]));
  12. }
  13. int main()
  14. {
  15. ios::sync_with_stdio(0);
  16. cin.tie(0);
  17. cout.tie(0);
  18.  
  19. cin>>n;
  20. cin>>s;
  21. for(int i=0; i<n; i++) cin>>a[i];
  22. cin>>t;
  23. for(int i=0; i<n; i++) cin>>b[i];
  24.  
  25. for (int i = 1; i <= n; i++)
  26. {
  27. for (int j = 1; j <= n; j++)
  28. {
  29. dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
  30. if (kt(i,j)) dp[i][j] = max(dp[i][j], dp[i-1][j-1] + a[i-1] + b[j-1]);
  31. }
  32. }
  33. cout<<dp[n][n];
  34. return 0;
  35.  
  36. }
  37.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty