80pts求助 WA #2,#8
  • 板块P2813 母舰
  • 楼主Cheese_int
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/10/22 08:03
  • 上次更新2023/10/27 06:35:19
查看原帖
80pts求助 WA #2,#8
753810
Cheese_int楼主2022/10/22 08:03
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <cstdlib>

using namespace std;

inline int read () {
	int w = 0, f = 1; char ch = getchar ();
	while (ch < '0' || ch > '9') {if (ch == '-') f = -1; ch = getchar ();}
	while (ch >= '0' && ch <= '9') {w = (w << 3) + (w << 1) + ch - '0'; ch = getchar ();}
	return w * f;
}

int m, n;
bool flag = 0;
int f[100050], g[100050];

bool cmp (int a, int b) {
	return a > b;
}

int main () {
	m = read (), n = read ();
	for (register int i = 1; i <= m; i++) {
		f[i] = read ();
	}
	for (register int i = 1; i <= n; i++) {
		g[i] = read ();
	}
	
	stable_sort (f + 1, f + 1 + m);
	stable_sort (g + 1, g + 1 + n);
	int ans = 0;
	for (register int i = 1; i <= m; i++) {
		for (register int j = 1; j <= n; j++) {
			if (g[j] > f[i]) {
				f[i] = g[j] = 0;
				flag = 1;
				break;
			} 
		}
		if (!flag) break;
	}
	
	for (register int i = 1; i <= n; i++) {
		if (g[i] == 0) continue;
		ans += g[i];
	}
	cout << ans;
 	return 0;
}

2022/10/22 08:03
加载中...