Hiện tại em đang làm 1 bài trên codeforces bài 505C và cùng 1 code nhưng trên codeforces và ideone đều chạy ngon lành nhưng khi em chạy ở coderunner thì lại ăn lỗi Terminated due to signal: SEGMENTATION FAULT (11) ạ :< mong mọi người giúp em, phần code đây ạ.
#include<bits/stdc++.h>
using namespace std;
const int M = 30001;
int dp[30001][500],gem[M],d;
bool used[30001][500];
int solve(int i, int j) {
int jj = j-(d-250);
if (i >= 30001) return 0;
if (used[i][jj]) return dp[i][jj];
used[i][jj] = true;
int res;
if (j==1) res=gem[i]+max(solve(i+j,j),solve(i+j+1,j+1));
else res=gem[i]+max(max(solve(i+j-1,j-1), solve(i+j,j)), solve(i+j+1,j+1));
dp[i][jj]=res;
return res;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n;
cin>>n>>d;
for (int i=1;i<=n;i++) {
int x;
cin>>x;
gem[x]++;
}
cout<<solve(d, d);
return 0;
}