#include #include #include #include #include #include #include using namespace std; typedef long long ll; struct UnionFind { vector data; UnionFind(int size) : data(size, -1) {} bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; int n, m; ll b[100000]; ll dif[100000]; int l[100000], r[100000]; void input(){ cin >> n >> m; for(int i = 0; i < n; i++){ cin >> b[i]; if(i%2 == 1) b[i] *= -1; } for(int i = 0; i < m; i++){ cin >> l[i] >> r[i]; l[i]--; r[i]--; } dif[0] = b[0]; dif[n] = -b[n-1]; for(int i = 1; i < n; i++){ dif[i] = b[i]-b[i-1]; } } void solve(){ UnionFind uf(n+1); for(int i = 0; i < m; i++){ uf.unionSet(l[i], r[i]+1); } vector root_sum(n+1); for(int i = 0; i <= n; i++){ int r = uf.root(i); root_sum[r] += dif[i]; } // for(int i = 0; i <= n; i++) cout << root_sum[i] << ' '; // cout << endl; for(int i = 0; i <= n; i++){ if(root_sum[i] != 0){ cout << "NO" << endl; return; } } cout << "YES" << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; input(); solve(); }