2 条题解
-
2鸟大师 (slz钟鼎皓) LV 8 @ 2024-4-9 17:23:40
#include <iostream> #include <cmath> using namespace std; long long f[100002],a[100002] = {0}; int main() { long long pos = 0, neg = 0; int n; cin>>n; cin>>a[1]; for(int i=2;i<=n;i++) { cin>>a[i]; f[i] = a[i]-a[i-1]; if(f[i]>0) pos +=f[i]; else if(f[i]<0) neg -=f[i]; } cout<<max(pos,neg)<<endl; cout<<abs(pos-neg)+1<<endl; return 0; }
-
22023-11-8 19:53:17@
#include <iostream> #include <cmath> using namespace std; long long f[100002],a[100002] = {0}; int main() { long long pos = 0, neg = 0; int n; cin>>n; cin>>a[1]; for(int i=2;i<=n;i++) { cin>>a[i]; f[i] = a[i]-a[i-1]; if(f[i]>0) pos +=f[i]; else if(f[i]<0) neg -=f[i]; } cout<<max(pos,neg)<<endl; cout<<abs(pos-neg)+1<<endl; return 0; }
- 1
信息
- ID
- 12
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 4
- 标签
- 递交数
- 287
- 已通过
- 140
- 上传者