HTML & JS
#include<bits/stdc++.h>
using namespace std;
 int i,j;
map<pair<int,int>,long long int>done;
long long int maxcoinhelp(long int arr[],int size,int last)
{    int i,j;

	long long int ans=0;
	if(size<0)
	return 0;
	pair<int,int>cur;
	cur=make_pair(last,size);
	if(done.find(cur)!=done.end())
	return done[cur];
	else
	{
	
	if(last==-1||(size+1)!=last)
	 ans=arr[size]+maxcoinhelp(arr,size-1,size);
	 return done[cur]=max(ans,maxcoinhelp(arr,size-1,-1));
   }
}
void maxcoin(long int arr[],int size,int i)
{
	
	if(size==0)
	cout<<"Case "<<i<<": 0"<<endl;
	else
	cout<<"Case "<<i<<": "<<maxcoinhelp(arr,size-1,-1)<<endl;
	done.clear();
}
int main()
{    int i,j;
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    for(i=1;i<=t;i++)
    {
	  int n;
    cin>>n;
    long int arr[100004];
    for(j=0;j<n;j++)
    cin>>arr[j];
    maxcoin(arr,n,i);
    }
    return 0;
}

Generated URL:

Output:

No Output
Report Bug