输出为什么不对

P4552 [Poetize6] IncDec Sequence

@[S_Z_Xcoco](/user/918508) 你看看两个输出一不一样不就知道错没错了吗?
by dsfgsdf @ 2023-08-22 16:48:22


```cpp #include<iostream> #include<cstdio> #include<algorithm> using namespace std; typedef long long LL; LL n,c,p,q,a[100010]; int main() { cin>>n; for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); } for(int i=2;i<=n;i++) { c=a[i]-a[i-1]; if(c>0) { p+=c; } else q-=c; } LL ans1=max(p,q); LL ans2=abs(p-q)+1; cout<<ans1<<endl<<ans2; return 0; } ``` 你看这里 ```cpp if(c>0) { p+=c; } else q-=c; ``` 如果c>0:p+=c; 如果c<0:q-=c; 众所周知减去一个负数就是加上一个正数 所以p,q都是正数
by Let_Fly @ 2023-08-22 16:55:55


@[S_Z_Xcoco](/user/918508) 全代码啊,没有其他的您让我怎么康啊
by FiraCode @ 2023-08-22 16:56:08


@[Let_Fly](/user/760859) 他说的是求和吧(
by FiraCode @ 2023-08-22 16:58:45


```cpp #include<bits/stdc++.h> #define int long long using namespace std; int n,a[100005],b[100005],s1,s2; signed main() { cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=2;i<=n;i++) { b[i]=a[i]-a[i-1]; if(b[i]>0)s1+=b[i]; else s2-=b[i]; } cout<<max(s1,s2)<<endl<<abs(s1-s2)+1; } ``` 这是我的代码,小于等于0的差分之和是用减法累加的,就相当于加法了,最后还是正数
by lcy_123 @ 2023-08-22 17:00:00


@[FiraCode](/user/528430) 鄂鄂,就是阿
by Let_Fly @ 2023-08-22 17:00:17


@[lcy12](/user/615490) namo,显然用减法就是正数啊
by FiraCode @ 2023-08-22 17:05:14


@[FiraCode](/user/528430) namo啥意思
by lcy_123 @ 2023-08-22 17:06:32


@[lcy12](/user/615490) <https://www.zhihu.com/question/397962962>,习惯性加入(
by FiraCode @ 2023-08-22 17:08:41


@[FiraCode](/user/528430) 6
by lcy_123 @ 2023-08-22 17:10:03


| 下一页