2 条题解
-
1
#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 1e5 + 10; typedef long long LL; int a[N], b[N]; int n; int main(){ cin >> n; for (int i = 1; i <= n; i ++ ) cin >> a[i]; for (int i = 1; i <= n; i ++ )b[i] = a[i] - a[i - 1]; LL p = 0,q = 0; for (int i = 2; i <= n; i++){ if(b[i] >0)p += b[i]; else q -= b[i]; } cout << max(p,q)<<endl; cout << abs(p - q)+1<< endl; return 0; }
- 1
信息
- ID
- 1240
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 1
- 标签
- 递交数
- 104
- 已通过
- 73
- 上传者