CodeForces 631A 631A - Interview

和最大连续子段差不多。
#include 
#include 

const int MAX = 1e3 + 5;
__int64 arr1[MAX], arr2[MAX];

int main()
{
	int num;
	std::cin >> num;
	for (int i = 1; i <= num; ++i)
	{
		std::cin >> arr1[i];
	}
	for (int i = 1; i <= num; ++i)
	{
		std::cin >> arr2[i];
	}
	__int64 max_sum = 0, curr_sum = 0, sum_a = 0, sum_b = 0;
	for (int i = 1; i <= num; ++i)
	{
		if (arr1[i] + arr2[i] > (arr1[i] | sum_a) + (arr2[i] | sum_b))
		{
			curr_sum = arr1[i] + arr2[i];
			sum_a = arr1[i];
			sum_b = arr2[i];
		}
		else
		{
			sum_a = (sum_a | arr1[i]);
			sum_b = (sum_b | arr2[i]);
			//std::cout << sum_a << sum_b << std::endl;
			curr_sum = sum_a + sum_b;
		}
		if (curr_sum >= max_sum)
		{
			max_sum = curr_sum;
		}
	}
	std::cout << max_sum << std::endl;

	return 0;
}

你可能感兴趣的:(CodeForces)