title: Codechef Wormholes: What's wrong with my logic?
body: <p>I've been trying to solve this <a href="https://www.codechef.com/ZCOPRAC/problems/ZCO12002" rel="nofollow noreferrer">problem</a> from <a href="https://www.codechef.com/" rel="nofollow noreferrer">Codechef</a>. But there's something wrong with my logic that I'm unable to correct and I cannot wait for editorials to come up because the contest runs for many days (like 200 days). </p>
  
  <p>My code: </p>
  
  <pre><code>#include &lt;bits/stdc++.h&gt;
  
  using namespace std;
  
  struct exam {int s,e;};
  
  int main() {
      int n,x,y;
      scanf("%d%d%d",&amp;n,&amp;x,&amp;y);
  
      exam ar[n];
      int v[x],w[y];
  
      for (int i = 0; i &lt; n; ++i) scanf("%d%d",&amp;ar[i].s,&amp;ar[i].e);
      for (int i = 0; i &lt; x; ++i) scanf("%d",&amp;v[i]);
      for (int i = 0; i &lt; y; ++i) scanf("%d",&amp;w[i]);
      stable_sort(v,v+x); stable_sort(w,w+y);
  
      int mini = 1e6;
  
      for (int i = 0; i &lt; n; ++i) {
  
          int *t1 = lower_bound(v,v+x,ar[i].s);
  
          if (*t1 &gt; ar[i].s &amp;&amp; t1 &gt; v) --t1;
          if (*t1 &gt; ar[i].s &amp;&amp; t1 == v) continue;
  
          int *t2 = lower_bound(w,w+y,ar[i].e);
  
          if (t2 == w+y) continue;
  
          mini = min(mini,(*t2-*t1)+1);
      }
  
      printf("%d",mini);
      return 0;
  }
  </code></pre>
  
  <p>And sadly this code doesn't pass two test cases: 
  <a href="https://i.stack.imgur.com/BrijL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BrijL.png" alt=""></a></p>
  
  <p>Can anyone tell me what's wrong with my logic?</p>