scheduling

PHOTO EMBED

Fri Nov 06 2020 17:32:33 GMT+0000 (UTC)

Saved by @Shami_Al #c++

/**
   SHAMI AL BASHAR PROTHOY
   PRESIDENCY INTERNATIONAL SCHOOL
**/

#include <bits/stdc++.h>
using namespace std;
#define csee "Case "<<cs<<": "
typedef long long ll;
typedef long double ld;
#define B begin()
#define E end()
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define ins insert
#define vi vector
#define ins insert
const ld pi=2*acos(0.0);
ll T,cs=1;
vi<ll>coins;
struct tim
{
    ll s,f;
};
bool cmp(tim a,tim b)
{
    if(a.s!=b.s)return a.s<b.s;
    return a.f<b.f;
}
/**
THINK TWICE,
      CODE ONCE
**/

void sol(ll cs)
{
   ll n,i,sum=1,j;
   cin>>n;
   tim t;
   vector<tim>v;
   for(i=0;i<n;i++)
    cin>>t.f>>t.s,v.pb(t);
   sort(v.B,v.E,cmp);//if time ain't sorted
   j=0;
   for(ll i=1;i<n;i++)
   {
       if(v[i].f>=v[j].s)sum++,j=i;
   }
   cout<<sum<<"\n";
}
//CODE
int main()
{
    //freopen("inp.txt","r",stdin)
    scanf("%lld",&T);
    while(T--)
        sol(cs++);
    return 0;
}
content_copyCOPY