IncDec序列
#include
<bits
/stdc
++.h
>
using namespace std
;
const int
N=1e5+10;
int n
;
int a
[N],b
[N];
long long neg
,pos
;
void insert(int l
,int r
,int c
)
{
b
[l
]+=c
;
b
[r
+1]-=c
;
}
int
main()
{
scanf("%d",&n
);
for(int i
=1;i
<=n
;i
++){
scanf("%d",&a
[i
]);
insert(i
,i
,a
[i
]);
}
for(int i
=2;i
<=n
;i
++){
if(b
[i
]>0) pos
+=b
[i
];
else neg
-=b
[i
];
}
cout
<<min(neg
,pos
)+abs(neg
-pos
)<<endl
;
cout
<<abs(neg
-pos
)+1<<endl
;
return 0;
}
转载请注明原文地址: https://lol.8miu.com/read-38400.html