#include<iostream>
#include<stdlib.h>
#include<math.h>
using namespace std;
// 存放子数组的和,以及左右下标
struct person{
int left, right;
int sum_b = 0;
};
int main()
{
int* a, * b;
// 创建结构体变量
person sum[2000];
int n, m, i, j;
int sum_a = 0, d = 0;
cin >> n >> m;
a = (int*)malloc(n * 4);
b = (int*)malloc(m * 4);
for (i = 1; i <= m; i++)
d += i;
for (i = 0; i < n; i++)
{
cin >> a[i];
sum_a += a[i];
}
for (i = 0; i < m; i++)
cin >> b[i];
// 初始化
sum[0].left = 0, sum[0].right = 0;
// 求和
for (i = 0; i < d; i++)
{
for (j = sum[i].left; j <= sum[i].right; j++)
sum[i].sum_b += b[j];
sum[i].sum_b = abs(sum[i].sum_b - sum_a);
// 左右下标判断
if (sum[i].right == m - 1)
{
sum[i + 1].left = sum[i].left + 1;
sum[i+1].right = sum[i + 1].left;
}
else
{
sum[i + 1].left = sum[i].left;
sum[i+1].right=sum[i].right+1;
}
}
// 判断输出
sum[d].left = sum[0].left;
sum[d].right = sum[0].right;
sum[d].sum_b = sum[0].sum_b;
for(i=1;i<d;i++)
if (sum[d].sum_b > sum[i].sum_b)
{
sum[d].left = sum[i].left;
sum[d].right = sum[i].right;
sum[d].sum_b = sum[i].sum_b;
}
for (i = sum[d].left; i <= sum[d].right; i++)
cout << b[i] << ' ';
cout << endl;
system("pause");
return 0;
}
#include<stdlib.h>
#include<math.h>
using namespace std;
// 存放子数组的和,以及左右下标
struct person{
int left, right;
int sum_b = 0;
};
int main()
{
int* a, * b;
// 创建结构体变量
person sum[2000];
int n, m, i, j;
int sum_a = 0, d = 0;
cin >> n >> m;
a = (int*)malloc(n * 4);
b = (int*)malloc(m * 4);
for (i = 1; i <= m; i++)
d += i;
for (i = 0; i < n; i++)
{
cin >> a[i];
sum_a += a[i];
}
for (i = 0; i < m; i++)
cin >> b[i];
// 初始化
sum[0].left = 0, sum[0].right = 0;
// 求和
for (i = 0; i < d; i++)
{
for (j = sum[i].left; j <= sum[i].right; j++)
sum[i].sum_b += b[j];
sum[i].sum_b = abs(sum[i].sum_b - sum_a);
// 左右下标判断
if (sum[i].right == m - 1)
{
sum[i + 1].left = sum[i].left + 1;
sum[i+1].right = sum[i + 1].left;
}
else
{
sum[i + 1].left = sum[i].left;
sum[i+1].right=sum[i].right+1;
}
}
// 判断输出
sum[d].left = sum[0].left;
sum[d].right = sum[0].right;
sum[d].sum_b = sum[0].sum_b;
for(i=1;i<d;i++)
if (sum[d].sum_b > sum[i].sum_b)
{
sum[d].left = sum[i].left;
sum[d].right = sum[i].right;
sum[d].sum_b = sum[i].sum_b;
}
for (i = sum[d].left; i <= sum[d].right; i++)
cout << b[i] << ' ';
cout << endl;
system("pause");
return 0;
}