Advertisement
vovanhoangtuan

31C - Schedule

Nov 6th, 2020 (edited)
2,210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5. int n;
  6. vector<int> output;
  7.  
  8.  
  9. struct Group{
  10.     int s, f, i;
  11.  
  12.  
  13.     Group(int start, int finish, int index)
  14.     {
  15.         s = start;
  16.         f = finish;
  17.         i = index;
  18.     }
  19.  
  20.     bool operator<(Group &p) {
  21.         if (s == p.s) return f < p.f;
  22.         return s < p.s;
  23.     }
  24. };
  25.  
  26. vector<Group> g;
  27.  
  28. void task()
  29. {
  30.     for (int i = 0; i < g.size(); i++)
  31.     {
  32.         bool check = true;
  33.         int startCurrent = 0;
  34.         int endCurrent = 0;
  35.  
  36.         for (int j = 0; j < g.size(); j++)
  37.         {
  38.             if (i == j) continue;
  39.             Group temp = g[j];
  40.             if (startCurrent < temp.s && startCurrent < temp.f && endCurrent <= temp.s && endCurrent < temp.f )
  41.             {
  42.                 startCurrent = temp.s;
  43.                 endCurrent = temp.f;
  44.             }else
  45.             {
  46.                 check = false;
  47.                 break;
  48.             }
  49.  
  50.         }
  51.  
  52.         if (!check) continue;
  53.         output.push_back(g[i].i);
  54.     }
  55. }
  56.  
  57.  
  58. int main()
  59. {
  60.     ios::sync_with_stdio(0);
  61.     cin.tie(0);
  62.     cout.tie(0);
  63.  
  64.     //freopen("input.txt", "r", stdin);
  65.  
  66.     cin >> n;
  67.     for (int i = 0; i < n; i++)
  68.     {
  69.         int l, r;
  70.         cin >> l >> r;
  71.         g.push_back(Group(l, r, i + 1));
  72.     }
  73.  
  74.     sort(g.begin(), g.end());
  75.  
  76.  
  77.     task();
  78.  
  79.  
  80.     sort(output.begin(), output.end());
  81.     cout << output.size() << endl;
  82.     for (auto it:output)
  83.     {
  84.         cout << it << " ";
  85.     }
  86.  
  87.     return 0;
  88. }
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement