Skip to content

Instantly share code, notes, and snippets.

@sealddr
Last active Oct 7, 2017
Embed
What would you like to do?
#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