fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define read(type) readInt<type>() // Fast read
  4. #define ll long long
  5. #define ld long double
  6. #define nL "\n"
  7. #define pb push_back
  8. #define mk make_pair
  9. #define pii pair<int, int>
  10. #define a first
  11. #define b second
  12. #define vi vector<int>
  13. #define all(x) (x).begin(), (x).end()
  14. #define umap unordered_map
  15. #define uset unordered_set
  16. #define MOD 1000000007
  17. #define imax INT_MAX
  18. #define imin INT_MIN
  19. #define exp 1e9
  20. #define sz(x) (int((x).size()))
  21. int freq[103];
  22.  
  23. bool comparator(const pair<pair<int,int>, pair<int,int>>& left, const pair<pair<int,int>, pair<int,int>>& right) {
  24. cout << "left: " << left.a.a << " " << left.a.b;
  25. cout << " right: " << right.a.a << " " << right.a.b << endl;
  26. double lc = 0;
  27. for(auto i = left.a.a; i <= left.a.b; i++) {
  28. if (freq[i] != 0) {lc++;}
  29. }
  30. cout << "lc " << lc << endl;
  31. double lr = (lc * (double)left.b.a) / (double)left.b.b;
  32.  
  33. double rc = 0;
  34. for(auto i = right.a.a; i <= right.a.b; i++) {
  35. if (freq[i] != 0) {rc++;}
  36. }
  37.  
  38. double rr = (lc * (double)right.b.a) / (double)right.b.b;
  39. cout << "left: " << lr << " right: " << rr << endl;
  40. return lr > rr;
  41. }
  42.  
  43.  
  44. void solve() {
  45. int n, m; cin >> n >> m;
  46. memset(freq, 0, sizeof(freq));
  47.  
  48. while(n--) {
  49. int u, v, c; cin >> u >> v >> c;
  50. for(auto i = u; i <= v; i++) {freq[i] = c;}
  51. }
  52.  
  53. vector<pair<pair<int,int>, pair<int, int>>> air;
  54. while(m--) {
  55. int s, t, c, m; cin >> s >> t >> c >> m;
  56. air.pb(mk(mk(s,t),mk(c,m)));
  57. }
  58.  
  59. sort(all(air), comparator);
  60.  
  61. for(auto p : air) {
  62. cout << "Init: " << p.a.a << " Dest: " << p.a.b << endl;
  63. }
  64.  
  65.  
  66. }
  67.  
  68.  
  69.  
  70. int32_t main()
  71. {
  72. ios_base::sync_with_stdio(false);
  73. cin.tie(NULL);
  74. solve();
  75. return 0;
  76. }
Success #stdin #stdout 0.01s 5472KB
stdin
2 4
1 5 2
7 9 3
2 9 2 3
1 6 2 8
1 2 4 2
6 9 1 5
stdout
left: 1 6 right: 2 9
lc 5
left: 1.25 right: 3.33333
left: 1 6 right: 2 9
lc 5
left: 1.25 right: 3.33333
left: 1 2 right: 2 9
lc 2
left: 4 right: 1.33333
left: 6 9 right: 1 2
lc 3
left: 0.6 right: 6
left: 6 9 right: 1 6
lc 3
left: 0.6 right: 0.75
Init: 1 Dest: 2
Init: 2 Dest: 9
Init: 1 Dest: 6
Init: 6 Dest: 9