Advertisement
AlexAvram

problema intervale

Feb 14th, 2023
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. ///problema nr.1 OLI 13.02
  2. #include <iostream>
  3. #include <fstream>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <utility>
  7. using namespace std;
  8. ifstream f("date.in");
  9. ofstream g("date.out");
  10. bool comp(pair<int,int>A, pair<int,int>B)
  11. {
  12.     if(A.first<B.first)
  13.         return 1;
  14.     else if(A.first==B.first && A.second<B.second)
  15.         return 1;
  16.  
  17.     return 0;
  18. }
  19. vector<pair<int, int>>v;
  20. int main()
  21. {
  22.     short n; int x, y;
  23.     f>>n;
  24.     v.resize(n+1);
  25.     short i, j;
  26.     for (i=1; i<=n; ++i)
  27.     {
  28.         f>>x>>y;
  29.         v[i]=make_pair(x, y);
  30.     }
  31.     sort(v.begin(), v.end(), comp);
  32.     int drmax=v[1].second, nrs=0;
  33.     for (i=2; i<=n; ++i)
  34.     {
  35.         if(v[i].second>drmax)
  36.             drmax=v[i].second;
  37.         else
  38.             ++nrs;
  39.     }
  40.     g<<nrs;
  41.     g<<'\n'<<'\n';
  42.     for (i=1; i<=n; ++i)
  43.         g<<v[i].first<<" "<<v[i].second<<'\n';
  44.  
  45.     return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement