I am trying to solve this problem arraysub on spoj. I have coded it using a sliding window concept and I am using a max-heap to store the elements of the current window. The problem constraints are of the order 10^5 and I am getting SIGABRT error for my submission. I've read on wiki that this error results if there's a memory leak or problem initialising large arrays. How do I deal with this? long long, long long int, long long unsigned int, doesn't seem to work. Please help. Below is my code:
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef pair<long, long> Pair;
long *a = new long[1000001], *output = new long[1000001];
long n, k;
void slidingWindowMax()
{
priority_queue<Pair> Q;
for(int i=0;i<k; i++)
Q.push(Pair(a[i], i));
for(int i=k; i<n; i++)
{
Pair p = Q.top();
output[i-k] = p.first;
while(p.second <= i-k)
{
Q.pop();
p = Q.top();
}
Q.push(Pair(a[i], i));
}
output[n-k] = Q.top().first;
for(int i=0;i<(n-k+1);i++)
{
cout << output[i] << " ";
}
}
int main()
{
cin >> n;
for(int i=0;i<n;i++)
cin >> a[i];
cin >> k;
slidingWindowMax();
return 0;
}