fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pll pair<ll,ll>
  5. #define F first
  6. #define S second
  7. #define sz(s) (int)s.size()
  8. #define max(p,q)((p)>(q)?(p):(q))
  9. #define fast ios::sync_with_stdio(0), cin.tie(0)
  10. #define N 100010
  11. ll n;
  12. pll a[N];
  13. int main() {
  14. fast;cout.tie(0);
  15. cin>>n;
  16. for(ll i=0;i<n;i++){
  17. cin>>a[i].F>>a[i].S;
  18. a[i].S=-a[i].S;
  19. }
  20. sort(a,a+n);//第一個越來越大,第二個越來越小
  21. for(ll i=0;i<n;i++)a[i].S=-a[i].S;
  22. int ans=1,mx=a[0].S,last=a[0].S;
  23. bool touch=0;
  24. for(ll i=1;i<n;i++){
  25. if(a[i].F>mx+1){
  26. cout<<-1<<endl;
  27. return 0;
  28. }
  29. if(!touch && a[i].S>last){
  30. touch=1;
  31. ans++;
  32. }
  33. }
  34. cout<<ans<<endl;
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5384KB
stdin
Standard input is empty
stdout
1