问下各位为啥开了long long 输出一堆不知名的数,还是说我的思路有问题
查看原帖
问下各位为啥开了long long 输出一堆不知名的数,还是说我的思路有问题
1334948
Auga楼主2024/7/15 22:03

问下各位为啥开了long long 输出一堆不知名的数,还是说我的思路有问题

#include <iostream>
#define int long long
const int N = 2e5 + 10;

void solve(){
    int n, m;
    std::cin >> n >> m;
    int ab[2][N];
    int end = n + m + 1;
    for (int i = 0; i < end; i++) std::cin >> ab[0][i];
    for (int i = 0; i < end; i++) std::cin >> ab[1][i];
    for (int i = 0; i < end; i++) {
        int ans = 0;
        int bc = 0;
        int cs = 0;
        for (int j = 0; j < end; j++) {
            if (j == i) continue;
            else if (ab[0][i] > ab[1][i]){
                if (bc == n){
                    ans += ab[1][i];
                    cs += 1;
                }
                else{
                    ans += ab[0][i];
                    bc += 1;
                }
            }
            else if (ab[0][i] < ab[1][i]){
                if (cs == m){
                    ans += ab[0][i];
                    bc += 1;
                }
                else{
                    ans += ab[1][i];
                    cs += 1;
                }
            }
        }
        std::cout << ans << ' ';
    }
}

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int t;
    std::cin >> t;
    while (t--){
        solve();
    }

    return 0;
}
2024/7/15 22:03
加载中...