跳到正文

题解

AT_abc373_c 题解

ikunTLE约 1 分钟
原文
文章信息与版本

文章信息

发布
2024年10月1日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 1 分钟
获赞
11

版本

  1. v1当前

题目传送门

思路

题目要求选择整数 i,ji,j,使 Ai+BjA_i+B_j 的值最大化,也就是要使 AiA_i 最大且 BjB_j 最大,即求序列 AA 的最大值与序列 BB 的最大值之和。

注意事项

  • 序列 AA 和序列 BB 中的值可能为负数。

AC CODE

C++
#include<bits/stdc++.h>
using namespace std;
int read(){int x=0;char f=1,ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();return x*f;}

int main(){
	int n=read();
	int max_a=INT_MIN;
	for(int i=1;i<=n;++i)
		max_a=max(max_a,read());
	int max_b=INT_MIN;
	for(int i=1;i<=n;++i)
		max_b=max(max_b,read());
	printf("%d\n",max_a+max_b);
	return 0;
}
原文
存档评论1 条抓取于