Question Name:CHOOSING THE JUDGES

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,count=0;
    cin>>t;
    while(t--)
    {count++;
        long long int n;
        cin>>n;
        long long int x,include=0,exclude=0,curr=0;
        for(long long int i=0;i<n;i++)
        {
            cin>>x;
            curr=max(include,exclude);
            include=exclude+x;
            exclude=curr;
        }
        long long int ans=max(include,exclude);
        cout<<"Case "<<count<<": "<<ans<<endl;
    }
}
  • Problem Description
    Harry was contesting to be the most stylist person in his college. He had to collect maximum points from the judges to be able to win. However there was a problem. 

    The judges were sitting in a line and each pair of adjacent judges had ego issues with each other. So if one judge gave X points to Harry then the next judge wont give him any points. 

    Harry had a friend in the organising team and through him he had found out the exact points he would get from each judge if he chose their score to be considered. Help him find out the maximum points he can score.

    INPUT
    The first line of input contains the number of test cases, T.
    0 <= T < = 10
    Each test case starts with a number N, the number of judges.
    0 <= N < = 10^4. 
    The next line will have N numbers, number of points each judge gave Harry
    0 < = X(i) < = 10^9.
    The order of the judges does not change.

    OUTPUT
    For each test case print Case T: A without quotes in a single line. 
    T is the case number, starting with 1.
    A is the maximum number of points Harry can collect.
  • Test Case 1
    Input (stdin)2
    5
    1 2 3 4 5
    1
    10
    Expected OutputCase 1: 9
    Case 2: 10
  • Test Case 2
    Input (stdin)4
    3
    4 5 2
    5
    1 3 2 5 4
    4
    5 6 7 2
    5
    2 5 1 3 4
    Expected OutputCase 1: 6
    Case 2: 8
    Case 3: 12
    Case 4: 9

Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro