Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. #define int double
  6.  
  7. using namespace std;
  8.  
  9.  
  10. bool compare(const vector<int>& a, const vector<int>& b){
  11. int x = (a[0] + a[1]) / 2;
  12. int y = (b[0] + b[1]) / 2;
  13. return x < y;
  14. }
  15.  
  16. signed main(){
  17. ios_base::sync_with_stdio(false);
  18. cout.tie(nullptr);
  19. cin.tie(nullptr);
  20. int32_t q;
  21. cin >> q;
  22. while (q--){
  23. int32_t n;
  24. cin >> n;
  25. vector<vector<int>> v(n, vector<int> (3));
  26. for (auto& x: v){
  27. cin >> x[0] >> x[1] >> x[2];
  28. }
  29. sort(v.begin(), v.end(), compare);
  30. int32_t flag = 1;
  31. int left = 0, m_prev = -1;
  32. for (auto& x: v){
  33. int m = (x[0] + x[1]) / 2;
  34. if (m_prev == -1){
  35. if (m == m_prev) {
  36. flag = 0;
  37. break;
  38. }
  39. } else{
  40. m_prev = m;
  41. }
  42. int l = max(left, x[0]);
  43. if (l + x[2] > x[1]){
  44. flag = 0;
  45. break;
  46. }
  47. left = l + x[2];
  48. }
  49. cout << flag << endl;
  50. }
  51. return 0;
  52.  
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement