Problem:
Score : 1400 points

Problem Statement

Snuke has a sequence of N integers x_1,x_2,\cdots,x_N.
Initially, all the elements are 0.

He can do the following two kinds of operations any number of times in any order:

Operation 1: choose an integer k (1 \leq k \leq N) and a non-decreasing sequence of k non-negative integers c_1,c_2,\cdots,c_k.
Then, for each i (1 \leq i \leq k), replace x_i with x_i+c_i.

Operation 2: choose an integer k (1 \leq k \leq N) and a non-increasing sequence of k non-negative integers c_1,c_2,\cdots,c_k.
Then, for each i (1 \leq i \leq k), replace x_{N-k+i} with x_{N-k+i}+c_i.

His objective is to have x_i=A_i for all i.
Find the minimum number of operations required to achieve it.

Constraints

1 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the minimum number of operations required to achieve Snuke's objective.

Sample Input 1

5
1 2 1 2 1

Sample Output 1

3

One way to achieve the objective in three operations is shown below.
The objective cannot be achieved in less than three operations.

Do Operation 1 and choose k=2,c=(1,2). Now we have x=(1,2,0,0,0).

Do Operation 1 and choose k=3,c=(0,0,1). Now we have x=(1,2,1,0,0).

Do Operation 2 and choose k=2,c=(2,1). Now we have x=(1,2,1,2,1).

Sample Input 2

5
2 1 2 1 2

Sample Output 2

2

Sample Input 3

15
541962451 761940280 182215520 378290929 211514670 802103642 28942109 641621418 380343684 526398645 81993818 14709769 139483158 444795625 40343083

Sample Output 3

7

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=200005;
ll a[N],c[N],n,sum;
multiset<ll> s;

int main(){
	read(n);
	rep(i,1,n){
		read(a[i]);
		c[i]=a[i]-a[i-1];
	}
	c[n+1]=-a[n];
	n+=1;

	s.insert(0);
	rep(i,1,n){
		if(c[i]>=0){
			s.insert(c[i]);
			sum+=c[i];
		}
		else if(c[i]<0){
			s.insert(-c[i]);
			int ex=-c[i],zero=0;
			while(ex){
				auto it=s.upper_bound(0);
				if(ex>=*it){
					ex-=*it;
					s.erase(it);
					zero++;
				}
				else{
					int nw=*it-ex;
					s.erase(it);
					s.insert(nw);
					ex=0;
				}
			}
			for(;zero;zero--){
				s.insert(zero);
			}
		}
		while(sum>a[i]){
			sum-=*(--s.end());
			s.erase(--s.end());
		}
	}
	cout<<n-(int)s.size()+1<<endl;

    return 0;
}