Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define NMAX 1000
- struct Interval {
- int a, b;
- } v[NMAX];
- int n;
- void read() {
- cin >> n;
- for (int i = 1; i <= n; i++)
- cin >> v[i].a >> v[i].b;
- }
- void sort() {
- for (int i = 1; i < n; i++)
- for (int j = i + 1; j <= n; j++)
- if (v[i].a > v[j].a)
- swap(v[i], v[j]);
- else if (v[i].a == v[j].a && v[i].b < v[j].b)
- swap (v[i], v[j]);
- }
- void greedy() {
- int b = 0, r = 0;
- for (int i = 1; i <= n; i++) {
- if (b < v[i].a) {
- b = v[i].b;
- r++;
- } else if (b >= v[i].a) {
- if (b < v[i].b) {
- b = v[i].b;
- r++;
- }
- }
- }
- cout << n - r << endl;
- }
- int main() {
- read();
- sort();
- greedy();
- return 0;
- }
Add Comment
Please, Sign In to add comment