#include<bits/stdc++.h>
using namespace std;
const int N = 1005;
int n,ans;
int a[N],b[N],c[N],vis[N];
int main()
{
cin>>n;
for(int i = 1;i <= n;i ++)
cin>>a[i];
for(int i = 1;i <= n;i ++)
cin>>b[i];
for(int i = 1;i <= n;i ++)
c[i] = b[i] - a[i];
for(int i = 1;i <= n;i ++)
{
if(vis[i])continue;
int res = c[i];
if(c[i] >= 0)
{
for(int j = i + 1;j <= n;j ++)
{
if(c[j] >= 0)
{
res = max(c[i],c[j]);
vis[j] = 1;
}
else
break;
}
}
else
{
for(int j = i + 1;j <= n;j ++)
{
if(c[j] <= 0)
{
res = min(c[i],c[j]);
vis[j] = 1;
}
else
break;
}
}
ans += abs(res);
}
cout<<ans<<'\n';
return 0;
}
↑蒟蒻的代码。。。求调!