AcWing 100. 增减序列
原题链接
中等
作者:
leimingze
,
2022-07-12 13:18:38
,
所有人可见
,
阅读 190
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double eps=1e-10;
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
void read(__int128 &x){char c = getchar();while (c != '-' & (c < '0' | c > '9'))c = getchar();if (c == '-') {c = getchar();while (c >= '0' & c <= '9') {x = x * 10 + c - '0';c = getchar();}x = 0 - x;} else {while (c >= '0' & c <= '9') {x = x * 10 + c - '0';c = getchar();}}}
void out(__int128 x) {string c = "";while (x) {c += x % 10 + '0';x /= 10;}reverse(c.begin(), c.end());cout << c << endl;}
int qmi(int a, int k, int p){int res = 1 % p;while (k){if (k & 1) res = Mod(res * a , p);a = Mod(a * a , p);k >>= 1;}return res;}
int _;
const int N=1e5+10;
int a[N];
int n;
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=n;i;i--)a[i]-=a[i-1];
int x=0,y=0;
for(int i=2;i<=n;i++)
{
if(a[i]<0)x-=a[i];
else y+=a[i];
}
cout<<min(x,y)+max(x,y)-min(x,y)<<endl;
cout<<max(x,y)-min(x,y)+1<<endl;
}
signed main()
{
io;
// cin>>_;
// while(_--)
solve();
return 0;
}