求助,很急,有关注,如果A了,万分感谢
  • 板块题目总版
  • 楼主CSP400pts
  • 当前回复4
  • 已保存回复5
  • 发布时间2024/10/13 19:47
  • 上次更新2024/10/13 22:03:04
查看原帖
求助,很急,有关注,如果A了,万分感谢
1331383
CSP400pts楼主2024/10/13 19:47


求助,有 22 个关注。
WA Code:

#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=1e5+5;
long long n,m,ans;
int a[N],b[N];
bool vis[N];
int main() {
	cin>>n>>m;
	for(int i=1; i<=n; i++) cin>>a[i];
	for(int i=1; i<=m; i++) cin>>b[i];
	sort(a+1,a+1+n);
	sort(b+1,b+1+m);
	int t=1;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			if(vis[j]) continue;
			if(b[j]>a[i]&&!vis[j]) {
				ans+=b[j];
				vis[j]=1;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
2024/10/13 19:47
加载中...