Question

I am not getting a SIGKILL error on my machine, and neither on the ideone.com online compiler Though it gives a SIGKILL on the spoj machine, cant figure out the reason EDIT: The program needs to use less than 256MB of data, presently it takes about 400MB How do i minimise the memory usage, i am using only the elements either on the diagonal or below it in the array 'c' Here is the code:

#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define r 1000000007
using namespace std;
int c[10000][10000];
int main(){_
int i,j,t;
c[0][0]=1;
for(i=1;i<10000;i++){
    c[i][0]=1;
    c[i][i]=1;
    for(j=1;j<i;j++){
        c[i][j]=c[i-1][j]+c[i-1][j-1];
        if(c[i][j]>=r){
            c[i][j]-=r;
        }
    }
}
cin>>t;
for(int f=1;f<=t;f++){
   int n,k,a[10000],ans=0;
   cin>>n>>k;
   for(i=0;i<n;i++){
    cin>>a[i];
   }
   sort(a,a+n);
   for(j=k-1;j<n;j++){
        ans+=((long long)a[j]*c[j][k-1])%r;
   }
   cout<<"Case #"<<f<<": "<<ans<<"\n";
}
return 0;
}
Was it helpful?

Solution

SPOJ imposes a memory limit, and your 2D array appears to exceed that limit: link.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top