Created
April 26, 2023 05:44
-
-
Save modos/6c7d7a699d4ad322858cab18d6ad6ee0 to your computer and use it in GitHub Desktop.
بیشترین تعداد بازه
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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