3 条题解

  • 0
    @ 2025-11-16 23:43:24
    #include <bits/stdc++.h>
    using namespace std;
    #define rep(i, l, r) for (int i = l; i <= r; i++)
    #define pii pair<int, int>
    #define int long long
    #define pb push_back
    #define se second
    #define fi first
    #define endl '\n'
    double pi = acos(-1);
    const int N = 1e6, mod = 1e9+7, inf = 1e18 + 5;
    int fpow(int a,int b){
        int res = 1;
        while(b){
            if(b&1) res = res * a % mod;
            a = a * a % mod;
            b >>= 1;
        }
        return res % mod;
    }
    void solve() {
        int n, m; cin >> n >> m; 
        vector<int> a(n + m + 2), b(n + m + 2);  
        for (int i = 1; i <= n + m + 1; i ++) cin >> a[i];
        for (int i = 1; i <= n + m + 1; i ++) cin >> b[i];
        int posa = n + m + 1; 
        int posb = n + m + 1; 
        int cnta = 1, cntb = 1;         
        int suma = 0, sumb = 0;              
        vector<bool> vis(n + m + 2, false); 
    
        for(int i = 1; i <= n + m; i++){
            if(a[i] > b[i]){  
                if(cnta <= n){  
                    cnta ++;
                    suma += a[i];
                    vis[i] = true; 
                } else { 
                    if(posa == n + m + 1) posa = i;  
                    if(cntb <= m){  
                        sumb += b[i]; 
                        cntb ++;
                    }
                }
            } else {  
                if(cntb <= m){ 
                    cntb ++;
                    sumb += b[i];
                } else { 
                    if(posb == n + m + 1) posb = i;  
                    if(cnta <= n){ 
                        suma += a[i]; 
                        cnta ++; 
                        vis[i] = true;
                    }
                }
            }
        }
        for(int i = 1; i <= n + m; i++){
            if(vis[i]){ 
                int ans = suma + sumb - a[i] + a[posa];  
                if(posa != n + m + 1){  
                    ans += b[posb] - b[posa];
                }
                cout << ans << ' ';
            }else{  
                int ans = suma + sumb - b[i] + b[posb]; 
                if (posb != n + m + 1){ 
                    ans += a[posa] - a[posb];
                }
                cout << ans << ' ';			
            }
        }
        cout << suma + sumb << endl;
    }
    signed main() {
        ios::sync_with_stdio(0); 
        cin.tie(0);
        cout.tie(0);
        int T = 1;
        cin >> T; 
        while (T--)
            solve();
        return 0;
    }
    

    信息

    ID
    1204
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    11
    已通过
    1
    上传者