Skip to content

Instantly share code, notes, and snippets.

@modos
Created April 26, 2023 05:44
Show Gist options
  • Save modos/6c7d7a699d4ad322858cab18d6ad6ee0 to your computer and use it in GitHub Desktop.
Save modos/6c7d7a699d4ad322858cab18d6ad6ee0 to your computer and use it in GitHub Desktop.
بیشترین تعداد بازه
// In the name of Allah
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
pair<int, int> reverse_segment[n];
for(int i = 0; i < n; i++)
cin >> reverse_segment[i].second >> reverse_segment[i].first;
sort(reverse_segment, reverse_segment + n);
int answer = 0, end_of_last_choosen_segment = 0;
for(int i = 0; i < n; i++)
if(reverse_segment[i].second >= end_of_last_choosen_segment)
answer++, end_of_last_choosen_segment = reverse_segment[i].first;
cout << answer << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment