Skip to content

Instantly share code, notes, and snippets.

@sealddr
Last active October 7, 2017 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sealddr/e7736acbc4b22c3f456e8e076ad0ecb8 to your computer and use it in GitHub Desktop.
Save sealddr/e7736acbc4b22c3f456e8e076ad0ecb8 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
// Here your code !
unsigned int MAX_N=100000;
unsigned int n;
int s[MAX_N]; // source
int t[MAX_N]; // sink
cin >> n;
cin.ignore();
for(int i=0;i<n;i++){
cin >> s[i];
}
cin.ignore();
for(int i=0;i<n;i++){
cin >> t[i];
}
vector<pair<int,int>> intervals(n);
for(int i=0;i<n;i++){
intervals[i].first = t[i];
intervals[i].second = s[i];
}
sort(intervals.begin(), intervals.end());
int count=0;
int cursor=0;
for(int i=0;i<n;i++){
if(cursor<intervals[i].second){
count++;
cursor=intervals[i].first;
}
}
cout << count << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment