这里可以白嫖关注
  • 板块灌水区
  • 楼主Kano_zyc
  • 当前回复9
  • 已保存回复9
  • 发布时间2023/10/17 22:25
  • 上次更新2023/11/2 13:09:31
查看原帖
这里可以白嫖关注
1076440
Kano_zyc楼主2023/10/17 22:25

rt,代码求调,全WA,题目

code

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2e5 + 10;
int t, n;
long long ans;

struct kano {
    int r, c, a;
} l[MAXN];

bool cmp(kano m, kano n) {
    return m.c > n.c;
}

void solve() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &l[i].r);
        l[i].a = i;
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d", &l[i].c);
    }

    // Sort based on contribution
    sort(l + 1, l + n + 1, cmp);

    ans = 0;
    for (int i = 1; i <= n; i++) {
        if (l[i].c > 0 && i < l[i].a) {
            ans += l[i].c;
        } else if (l[i].c < 0 && i > l[i].a) {
            ans -= l[i].c;
        }
    }

    printf("%lld\n", ans);
}

int main() {
    scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}
2023/10/17 22:25
加载中...