title: Why is my c++ code unable to scale up input?
body: <p>Here is my code for a problem in CSES problem set &quot;Distinct Numbers&quot;. The problem basically inputs an integer (<code>i</code>) specifying the no. of elements and and an array of length equal <code>i</code>. We basically have to find the distinct no. of elements in that array.</p>
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  bool check(unsigned long long int val, unsigned long long int arr[], unsigned long long int range) {
      unsigned long long int i;
      bool return_val = true;
      for (i=0; i&lt;range; i++) {
          if (arr[i] == val) {
              return_val = false;
          }
      }
      return return_val;
  }
  
  int main()
  {
      //cout &lt;&lt; &quot;DEBUG-1&quot; &lt;&lt; endl;
      unsigned long long int i;
      cin &gt;&gt; i;
  
      unsigned long long int in_array[i];
      unsigned long long int j;
      for (j=0; j&lt;i; j++) {
          cin &gt;&gt; in_array[j];
      }
      unsigned long long int sort_array[i];
      unsigned long int long sort_array_index = 0;
      for (j=0; j&lt;i; j++) {
          if(check(in_array[j], sort_array, sort_array_index)) {
              sort_array[sort_array_index] = in_array[j];
              sort_array_index++;
           }
      }
      cout &lt;&lt; sort_array_index;
  }
  </code></pre>
  <p>When the input is not huge and is limited to 2 digit inputs, the code works fine.</p>
  <p>The problem I'm facing is that when the input is 200000, my code breaks and shows there is no output as the time limit for compilation exceeds 1 second. Here is my issue: There's a test case on the site in which i=200000, and the array consists of all 1's. The obvious answer is 1 and my output is also 1. But, when i=200000, and all values are distinct the above issue occurs and the input displayed on the test is (empty).</p>
  <p>Even when I include the first <code>cout &lt;&lt; &quot;DEBUG-1&quot; &lt;&lt; endl;</code> line (commented out), it is not seen in the output, whereas it is even before the first input line. It's like the program just rejects the input on seeing it. What I'm not able to understand that I wrote a similar program for an earlier problem and it worked fine on big inputs. Please tell me what is going wrong and include suggestions to write better code as well.</p>