10pts 求助!!!!
查看原帖
10pts 求助!!!!
1251905
cao_20115楼主2024/5/2 18:14

10pts!

Talk is cheap,show you my code.

#include <bits/stdc++.h>
using namespace std;
int n, ans, fre[10086];
bool c;
struct game{
    int r, t;
}a[10086];
bool cmp(game a, game b) {
    if (a.r >= b.r) return true;
    else return false;
}
int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i].t);
    }
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i].r);
    }
    sort(a + 1, a + n + 1, cmp);
    for (int i = 1; i <= n; ++i) {
        c = false;
        for (int j = a[i].t; j >= 1; --j) {
            if (fre[j] == 0) {
                fre[j]== 1;
                c = true;
                break;
            }
        }
        if (c) ans += a[i].r;
    }
    printf("%d", ans);
    return 0;
}

救救孩子

2024/5/2 18:14
加载中...