#include<iostream>
using namespace std;
int n,a,b,x;
int main(){
cin>>n;
while(n--)cin>>x,(x>0)&&(a++),(x<0)&&(b++);
while(a&&b)cout<<1<<' '<<-1<<' ',a--,b--;
while(a)cout<<1<<' ',a--;
while(b)cout<<-1<<' ',b--;
return 0;
}
对于此代码
输入
4
1 1 -1 -1
输出
1 -1 1 -1
最大字段和为2
然而若将该序列重排为
1 -1 -1 1
最大字段和显然为1
谁能解释一下???