input:choose.in output:choose.out

时间限制: 1000 ms 空间限制: 262144 KB

题目描述

输入

输出

样例输入1

1
2
3
3
4 2 3
3 4 2

样例输入2

1
2
3
5
38 19 5 17 3
15 22 0 6 17

样例输出1

1
0

样例输出2

1
1

数据范围限制

提示

【样例解释】样例一:L = 1, R = 3 样例二:L = 2, R = 5

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <bits/stdc++.h>
#define rr register
#define int long long
using namespace std;
int n,a[2][300005],c[300005];
namespace YOUAREJULUO {
int abs(int a)
{
if(a<0)
return -a;
return a;
}
int min(int a,int b)
{
if(a>b)
return b;
return a;
}
}
signed main()
{
freopen("choose.in","r",stdin);
freopen("choose.out","w",stdout);
int tmp;
scanf("%lld",&n);
for(rr int i=1;i<=n;i++)
{
scanf("%lld",&a[0][i]);
}
for(rr int i=1;i<=n;i++)
{
scanf("%lld",&a[1][i]);
c[i]=c[i-1]+a[0][i]-a[1][i];
}
int Min=(1<<30);
sort(c,c+n+1);
for(rr int i=1;i<=n;i++)
{
Min=YOUAREJULUO::min(Min,YOUAREJULUO::abs(c[i]-c[i-1]));
}
printf("%lld",Min);
}