题目很水,贪心时注意一下即可
2026-02-11 12:23:35
发布于:广东
9阅读
0回复
0点赞
以下为代码:
#include<bits/stdc++.h>
using namespace std;
long long n,m,mx=-1e4+3,x;//这个mx要赋值为最小,不然要是熟练度都是负数,会直接变为0(如第一个测试点)
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>x;
mx=max(x,mx);
}
for(int i=0;i<m;i++){
cin>>x;
if(x>=0) mx+=x;
else if(x<0 and n==1) mx+=x;//最倒霉的情况只有这一把武器,是负数也得用它
}
cout<<mx;
return 0;
}
这里空空如也





有帮助,赞一个