Advertisement
MathQ_

Untitled

Aug 1st, 2023
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <set>
  5. #include <algorithm>
  6. #include <numeric>
  7. #include <queue>
  8. #include <deque>
  9. #include <cmath>
  10.  
  11. using namespace std;
  12.  
  13. typedef long long ll;
  14. typedef unsigned long long ull;
  15. typedef long double ld;
  16. typedef pair<int, int> pii;
  17. typedef pair<ll, ll> pll;
  18.  
  19. #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  20. #define file_in freopen("input.txt", "r", stdin);
  21. #define all(x) (x).begin(), (x).end()
  22. #define sz(x) (int)x.size()
  23. #define fi first
  24. #define se second
  25.  
  26. template<typename T> istream& operator>>(istream &in, vector<T> &v) { for (auto &el : v) { in >> el; } return in; }
  27. template<typename T> ostream& operator<<(ostream &out, const vector<T> &v) { for (auto &el : v) { out << el << " "; } return out; }
  28. template<typename T1, typename T2> istream& operator>>(istream &in, pair<T1, T2> &v) { in >> v.fi >> v.se; return in; }
  29. template<typename T1, typename T2> ostream& operator<<(ostream &out, const pair<T1, T2> &v) { out << v.fi << " " << v.se; return out; }
  30.  
  31. void solve() {
  32.     int n;
  33.     cin >> n;
  34.     vector<vector<int>> a(n, vector<int>(3));
  35.     cin >> a;
  36.     sort(all(a), [](vector<int> &l, vector<int> &r){ return l[1] - l[2] < r[1] - r[2]; });
  37.     int last = a[0][0] + a[0][2];
  38.     for (int i = 1; i < sz(a); ++i) {
  39.         if (a[i][1] - max(a[i][0], last) >= a[i][2]) {
  40.             last = max(a[i][0], last) + a[i][2];
  41.         } else {
  42.             cout << 0 << '\n';
  43.             return;
  44.         }
  45.     }
  46.     cout << 1 << '\n';
  47. }
  48.  
  49. int main() {
  50.     fast
  51.     // file_in
  52.  
  53.     int t;
  54.     cin >> t;
  55.     while (t--) {
  56.         solve();
  57.     }
  58.     return 0;
  59. }
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement