Why are 4 test cases not passing?

this one is the right one https://ide.codingblocks.com/s/205540

I made some changes in the code… minor changes indicating essence of dynamic programming… try to understand it and let me know if problem still exists.

#include
#include<bits/stdc++.h>
using namespace std;
int main() {
int n,a,count=0,count1=0;
cin>>n;
int arr[100001]={0};
for(int i=0;i<n;i++)
{
cin>>a;
arr[a]=arr[a]+1;
}
int ans[100001]={0};
ans[1] = arr[1];
for (int i = 2; i<=100000; i++)
{
ans[i] = max(ans[i - 1], ans[i - 2] + arr[i]*i);
}
cout<<ans[100000]<<endl;
}

thanns