-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13.cpp
More file actions
32 lines (31 loc) · 673 Bytes
/
13.cpp
File metadata and controls
32 lines (31 loc) · 673 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(){
//program to merge intervals.
int n;
cin>>n;
int arr[n][2];
for(int i=0;i<n;i++){
cin>>arr[i][0]>>arr[i][1];
}
sort(arr, arr + n);
int b = arr[0][0];
int e = arr[0][1];
vector<vector<int>> ans;
for(int i=1;i<n;i++){
if(e>=arr[i][0]){
e = max(arr[i][1], e);
}else{
vector<int> temp;
temp.push_back(b);
temp.push_back(e);
ans.push_back(temp);
}
}
vector<int> temp;
temp.push_back(b);
temp.push_back(e);
ans.push_back(temp);
return 0;
}