Untitled

mail@pastecode.io avatarunknown
plain_text
a month ago
840 B
6
Indexable
Never
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;


int main() {
    
    int n;cin>>n;
    vector<int>start(n);
    vector<int>end(n);
    
    
    
    for(int i=0;i<n;i++) {
        cin>>start[i];
    }

    for(int i=0;i<n;i++) {
        cin>>end[i];
        end[i]++;
    }
    sort(start.begin(),start.end());
    sort(end.begin(),end.end());
    
    
    
    int i = 1,j = 0;
    
    int maxHeight = 1;
    int height = 1;
    int ans = start[0];
    while(i<n && j<n) {
        if(start[i]<end[j]) {
            height++;
            if(maxHeight<height) {
                maxHeight = height;
                ans = start[i];
            }
            i++;
        } else {
            height--;
            j++;
        }
    }
    
    cout<<ans<<endl;
    return 0;

}
/*
    

*/