Problem: Wormholes

My Solution: 70/100 Partial AC

```
#include <bits/stdc++.h>
using namespace std;
#define scin(a) scanf("%d",&(a))
#define prin(a) printf("%d",(a))
int main() {
int N, X, Y;
scin(N);
scin(X);
scin(Y);
vector<int> V(X), W(Y);
vector<pair<int, int>> cont(N);
for (int i = 0; i < N; i++)
scanf("%d %d", &cont[i].first, &cont[i].second);
for (int i = 0; i < X; i++)
scin(V[i]);
for (int i = 0; i < Y; i++)
scin(W[i]);
sort(V.begin(), V.end());
sort(W.begin(), W.end());
int mn = INT_MAX, start, end, v, w;
for (auto i:cont) {
start = i.first;
end = i.second;
if (lower_bound(W.begin(), W.end(), end) != W.end())
w = *lower_bound(W.begin(), W.end(), end);
auto vIter = upper_bound(V.begin(), V.end(), start);
if (vIter == V.end() || vIter == V.begin())
continue;
else
--vIter;
v = *vIter;
mn = min(mn, abs(w - v) + 1);
}
prin(mn);
return 0;
}
```

My approach:

I sort the entering and exiting wormholes according to time.

Then for each contest, I check for the minimum time possible. I fail in two sub-tasks, but I can’t figure out why!

Thanks in advance!

Arnav