文件目录

#include <bits/stdc++.h>
using namespace std;
int n, a[1005], b[1005], c[1005];
int dp[1005][1005][3]; // 第i轮 换j次 当前牌为k的最大分数
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i < n; i++)
        cin >> b[i];
    for (int i = 1; i <= n; i++)
        cin >> c[i];
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < i; j++)
            for (int k = 0; k <= 2; k++)
            {
                int fen = 0;
                int t = -999999999;
                if ((c[i] + 1) % 3 == k)
                    fen = a[i] * 2;
                else if (c[i] == k)
                    fen = a[i];
                if (j < i - 1 || i == 1) // 不换牌
                    t = max(t, dp[i - 1][j][k]);
                if (j > 0) // 换牌
                    t = max(t, max(dp[i - 1][j - 1][(k + 1) % 3], dp[i - 1][j - 1][(k + 2) % 3]) - b[j]);
                dp[i][j][k] = t + fen;
            }
    int ans = -999999999;
    for (int i = 0; i < n; i++)
    {
        ans = max(ans, dp[n][i][0]);
        ans = max(ans, dp[n][i][1]);
        ans = max(ans, dp[n][i][2]);
    }
    cout << ans;
    return 0;
}