TLE0分求调

忙碌的老师

image
image

#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
bool cmp(pair<int,int>a,pair<int,int>b){
  if(a.f==b.f)return a.s<b.s;
  return a.f<b.f;
}int main(){
  int n,m,p,last,ans=0;
  pair<int,int>a[100001];
  set<int>st;
  cin>>n;m=n;
  for(int i=0;i<n;i++){
    cin>>a[i].f>>a[i].s;
    st.insert(i);
  }sort(a,a+n,cmp);
  while(m){
    last=a[*st.begin()].s;
    for(auto i=*st.begin();i!=*st.end();){
      if(a[i].f>last)continue;
      m--;
      last=a[i].s;
      i++;
      st.erase(i-1);
    }ans++;
  }cout<<ans;
  return 0;
}

哪节课?