This is the typical use case for the debugger. Your rist issue is that your output is very little. A better information about the running state of the code is important.
My tip is that your res is wrong and/or not needed.
long long dp[100005]={0};
long long count1[100005]={0};
for(int i=2;i<(n+2);i++){
dp[i]=max(dp[i-1],dp[i-2]+i*count1[i]);
}