Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- class gfg
- {
- public:
- bool satisfiable(std::vector<int> a, std::vector<int> b) {
- while (!a.empty()) {
- std::sort(b.begin(), b.end(), std::greater<int>());
- int k = a.back();
- a.pop_back();
- if (k > b.size()) return false;
- if (k == 0) continue;
- if (b[k - 1] == 0) return false;
- for (int i = 0; i < k; i++)
- b[i]--;
- }
- for (std::vector<int>::iterator i = b.begin(); i != b.end(); i++)
- if (*i != 0)
- return false;
- return true;
- }
- };
- int main()
- {
- gfg g;
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int r,c,n,cnt=0;
- cin >> n;
- while(cnt<n){
- cnt++;
- cin >> r >> c;
- int x;
- vector<int> a;
- vector<int> b;
- for(int i=0;i<r;i++){
- cin >> x;
- a.push_back(x);
- }
- for(int j=0;j<c;j++){
- cin >> x;
- b.push_back(x);
- }
- if(g.satisfiable(a,b)) cout << "YESn";
- else cout << "NOn";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement