TLE,20pts求调
  • 板块P2813 母舰
  • 楼主cao_20115
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/5/3 19:33
  • 上次更新2024/5/3 21:37:12
查看原帖
TLE,20pts求调
1251905
cao_20115楼主2024/5/3 19:33

Code

#include <cstdio>
#include <algorithm>
using namespace std;
int df, wf, ans;
int c1 = 1, c2 = 1, c3;
bool flag;
int d[100010], w[100010];
int main(){
    scanf("%d%d", &df, &wf);
    for (int i = 1; i <= df; ++i) {
        scanf("%d", &d[i]);
    }
    for (int i = 1; i <= wf; ++i) {
        scanf("%d", &w[i]);
    }
    sort(d + 1, d + 1 + df);
    sort(w + 1, w + wf + 1);
    while (c1 != df + 1) {
        if (c1 != df + 1 && c2 == wf + 1) {
            printf("0");
            return 0;
        }
        if (d[c1] == 0) {
            c1++;
        }
        if (d[c1] < w[c2]) {
            w[c2] = 0;
            c1++;
            c2++;
            continue;
        }
        if (d[c1] > w[c2]) {
            c2++;
            continue;
        }
    }
    for (int i = 1; i <= wf; ++i) {
        ans+=w[i];
    }
    printf("%d", ans);
    return 0;
}
2024/5/3 19:33
加载中...