Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. class gfg
  7. {
  8. public:
  9. bool satisfiable(std::vector<int> a, std::vector<int> b) {
  10. while (!a.empty()) {
  11. std::sort(b.begin(), b.end(), std::greater<int>());
  12. int k = a.back();
  13. a.pop_back();
  14. if (k > b.size()) return false;
  15. if (k == 0) continue;
  16. if (b[k - 1] == 0) return false;
  17. for (int i = 0; i < k; i++)
  18. b[i]--;
  19. }
  20. for (std::vector<int>::iterator i = b.begin(); i != b.end(); i++)
  21. if (*i != 0)
  22. return false;
  23. return true;
  24. }
  25.  
  26. };
  27.  
  28.  
  29. int main()
  30. {
  31. gfg g;
  32. ios_base::sync_with_stdio(false);
  33. cin.tie(NULL);
  34.  
  35. int r,c,n,cnt=0;
  36. cin >> n;
  37. while(cnt<n){
  38. cnt++;
  39. cin >> r >> c;
  40. int x;
  41. vector<int> a;
  42. vector<int> b;
  43. for(int i=0;i<r;i++){
  44. cin >> x;
  45. a.push_back(x);
  46. }
  47.  
  48. for(int j=0;j<c;j++){
  49. cin >> x;
  50. b.push_back(x);
  51. }
  52.  
  53.  
  54.  
  55. if(g.satisfiable(a,b)) cout << "YESn";
  56. else cout << "NOn";
  57. }
  58.  
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement