E/F题目 看起来简单的代码,会点语法应该就能看懂, 思路和题解一样的

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e4+1;
int n, m;
int a[N];
bool dp[N][N];
int pre[N][N];
void query(int n)
{

    for (int i = 1; i <= n / i ; i ++ )
    {
        if (n % i) continue;
        int x = i, y = n / i;
        vector<int> vx, vy;
        if (dp[x][y] && pre[x][y] != 0) {
            while (pre[x][y] != 0)
            {
                if (pre[x][y] > 0)
                    vx.push_back(pre[x][y]), x -= pre[x][y];
                else  vy.push_back((-1) * pre[x][y]), y += pre[x][y];
            }
            cout << "Yes\n";
            cout << vx.size() << " " << vy.size() << "\n";
            for (auto _ : vx)
                cout << _ << " ";
            cout << "\n";
            for (auto _ : vy)
                cout << _ << " ";
            cout << "\n";
            return ;
        }

    }
    cout << "No\n";
}
void solve()
{
    cin >> n >> m;
    for (int i = 0; i < n; i ++ )
        cin >> a[i];

    dp[0][0] = 1;

    for (int i = 0; i < n; i ++ )
        for (int x = N-1; x >= 0; x -- )
            for (int y = (x == 0 ? 10000 : 10000 / x); y >= 0;  y -- )
    {
        if (dp[x][y]) continue;
        if (x >= a[i] && dp[x - a[i]][y] )
        {
            dp[x][y] = dp[x - a[i]][y];
            pre[x][y] = a[i];
        }
        else if (y >= a[i] && dp[x][y - a[i]])
        {
            dp[x][y] = dp[x][y - a[i]];
            pre[x][y] = a[i] * (-1);
        }
    }

    while ( m -- )
    {
        int x;
        cin >> x;
        query(x);
    }

}

int main()
{

    int T;
    T = 1;
    //cin >> T;
    while (T -- )
    {
        solve();
    }
    return 0;
}