0

if i declare q[30005] inside func testcase() code doesnt seem to work but if i declare it globally or take smaller size like 2000 code runs fine

#include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    // ll q[300005];
    void testcase() {
      ll n; ll q[300005];
      cin >> n;
    
      for(int i = 0; i < n; i++)  cin >> q[i];
    
      deque <ll> nq;
      nq.push_back(q[0]);
      for(int i = 1; i < n; i++) {
        if(nq.front() >= q[i]) nq.push_front(q[i]);
        else  nq.push_back(q[i]);
      }
      for(int i = 0; i < n; i++)  cout << nq[i] << " ";
      cout << "\n";
    }
    
    int main() {
      int t;
      cin >> t;
      while(t--) {
        testcase();
      }
      return 0;
    }
nobody
  • 19,814
  • 17
  • 56
  • 77
  • 2
    Are you aware of how much memory `300005 * sizeof(long long)` requires? And how much stack space you have? – UnholySheep Sep 29 '21 at 09:36
  • it would be very large. actually somebody used this in one of the editorial. I accidentally declared it inside testcase() and it didnt work. So can u explain whats actually happening here? – ayush negi Sep 29 '21 at 13:27

0 Answers0