title: Codeforces 519B Using Vectors vs Some Other Container
body: <p>To solve <a href="https://codeforces.com/problemset/problem/519/B" rel="nofollow noreferrer">519B</a> I created three vectors that each hold different numbers and occurrences of those numbers for each line. These vectors are also sorted.</p>
  <p>eg if the line was 1 1 3 2, the vector would store &lt;1, 2&gt;, &lt;2, 1&gt;, &lt;3, 1&gt;</p>
  <p>From there, I would compare one pair from one vector with the pair from the next vector to find the missing number.</p>
  <p>This passes most test cases until there are a large number of numbers in each line. I actually saw the answer for this question, but it uses a different method to find the answer. However, I would like to know if there is a way to solve the question with &quot;my way.&quot; I read online that using maps and other containers could yield a faster result, but I'm skeptical that using another container would really make that big of a difference. Any thoughts?</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  
  int has(std::vector&lt;std::pair&lt;int, int&gt;&gt; &amp;error, int i) {
      for (int j = 0; j &lt; error.size(); j++) {
          if (error[j].first == i) {
              return j;
          }
      }
  
      return -1;
  }
  
  std::vector&lt;std::pair&lt;int, int&gt;&gt; generate(int n) {
      int temp;
      std::vector&lt;std::pair&lt;int, int&gt;&gt; tempVec;
  
      for (int i = 0; i &lt; n; i++) {
          std::cin &gt;&gt; temp;
          int pos = has(tempVec, temp);
          if (pos != -1) {
              tempVec[pos].second++;
          } else {
              tempVec.push_back(std::make_pair(temp, 1));
          }
      }
  
      return tempVec;
  }
  
  bool sortPair(const std::pair&lt;int, int&gt; &amp;a, const std::pair&lt;int, int&gt; &amp;b) {
      return a.first &lt; b.first;
  }
  
  int main() {
      int n, temp;
      std::cin &gt;&gt; n;
  
      std::vector&lt;std::pair&lt;int, int&gt;&gt; a = generate(n), b = generate(n - 1), c = generate(n - 2);
      std::sort(a.begin(), a.end(), sortPair);
      std::sort(b.begin(), b.end(), sortPair);
      std::sort(c.begin(), c.end(), sortPair);
  
      bool found = false;
  
      for (int i = 0; i &lt; n - 1; i++) {
          if (a[i] != b[i]) {
              found = true;
              std::cout &lt;&lt; a[i].first &lt;&lt; std::endl;
              break;
          }
      }
  
      if (!found) {
          std::cout &lt;&lt; a[n - 1].first &lt;&lt; std::endl;
      }
  
      bool found2 = false;
  
      for (int i = 0; i &lt; n - 2; i++) {
          if (b[i] != c[i]) {
              found2 = true;
              std::cout &lt;&lt; b[i].first &lt;&lt; std::endl;
              break;
          }
      }
  
      if (!found2) {
          std::cout &lt;&lt; b[n - 2].first &lt;&lt; std::endl;
      }
  }
  </code></pre>