/* Solution to Plugging Wires by Mees * * Uses a priority queue * * Expected answer: ACCEPTED. * */ #include #include #include #include using namespace std; int main() { int n, m; cin >> n >> m; vector x(n), l(m); for(int i = 0; i < n; i++) cin >> x[i]; for(int i = 0; i < m; i++) cin >> l[i]; sort(x.begin(), x.end()); sort(l.begin(), l.end()); priority_queue>> q; set> done; for(int i = 0; i < n - 1; i++) { q.push(make_pair(x[i]-x[i+1], make_pair(i, i+1))); done.insert(make_pair(i, i+1)); } for(int j = 0; j < m; j++) { if(q.empty()) { cout << "NO" << endl; return 0; } auto t = q.top(); q.pop(); if(-t.first > l[j]) { cout << "NO" << endl; return 0; } int i1 = t.second.first; int i2 = t.second.second; auto pr = make_pair(i1, i2+1); if(i2 + 1 < n && done.find(pr) == done.end()) { q.push(make_pair(x[i1]-x[i2 + 1], make_pair(i1, i2+1))); done.insert(pr); } } cout << "YES" << endl; return 0; }