Page 2 of 2

Re: 12032

Posted: Sun Aug 03, 2014 8:20 am
by Shahidul.CSE
My code giving correct output for every sample input given on this topic . But having WA. Whats wrong with my code?

Code: Select all

#include<stdio.h>
int main()
{
    long long int t,n,r[100010],c,i,max,k,dif;
    scanf("%lld",&t);
    for(c=1;c<=t;c++)
    {
        scanf("%lld",&n);
        for(i=1;i<=n;i++)
            scanf("%lld",&r[i]);
        max=0;
        for(i=1;i<n;i++)
        {
            dif=r[i+1]-r[i];
            if(dif>max)
                max=dif;
        }
        k=max;
        for(i=1;i<n;i++)
        {
            dif=r[i+1]-r[i];
            if(dif>k)
            {
                max+=dif-k;
                k+=dif-k;
            }
            if(dif==k)
                k--;
        }
        if(r[1]>max)
            max=r[1];
        printf("Case %lld: %lld\n",c,max);
    }
    return 0;
}

Re: 12032

Posted: Sun Aug 03, 2014 7:11 pm
by lbv
Shahidul.CSE wrote:My code giving correct output for every sample input given on this topic . But having WA. Whats wrong with my code?
You may try:

Input

Code: Select all

2
4
4 7 9 11
6
5 9 12 14 15 20
Output

Code: Select all

Case 1: 5
Case 2: 6

Re: 12032 - The Monkey and the Oiled Bamboo

Posted: Wed Sep 17, 2014 6:49 pm
by RedCode119
I check all the test cases, but can't find out why getting WS , Here's the code

Code: Select all

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    long long t,n,h[100005],i,m,check,cnt,k;
    cnt=1;
    cin>>t;
    while(t)
    {
        cin>>n;
        for(i=0; i<n; i++)
        {
            cin>>h[i];
        }
        m=0;
        for(i=0; i<n-1; i++)
        {
            check=abs(h[i]-h[i+1]);
            if(check>m)
                m=check;
        }
        k=m;

        for(i=0; i<n-1; i++)
        {
            if(i==0)
            {
                if(h[0]>m)
                {
                        k++;
                        m=k;
                        i=-1;
                    continue;
                }
                if(h[0]==m)
                    m--;

            }

            check=abs(h[i]-h[i+1]);
            if(check>m)
            {
                k++;
                m=k;
                i=-1;
                continue;
            }
            if(check==m)
                m--;



        }
        cout<<"Case "<<cnt<<": "<<k<<endl;
        cnt++;
        t--;

    }
    return 0;
}

Re: 12032 - The Monkey and the Oiled Bamboo

Posted: Wed Sep 17, 2014 9:19 pm
by brianfry713
Try a case where n = 1.

Re: 12032 - The Monkey and the Oiled Bamboo

Posted: Wed Sep 17, 2014 11:46 pm
by RedCode119
Thnx a lot Brainfry, Accepted

Re: 12032 - The Monkey and the Oiled Bamboo

Posted: Sat Nov 29, 2014 4:11 pm
by ehsanulbigboss
Thanks to brianfry713

Re: 12032 - The Monkey and the Oiled Bamboo

Posted: Wed Dec 03, 2014 1:12 am
by brianfry713
Change line 21 to:
for (i=1 ; i <= n ; i++)
Change line 29 from max+=2 to break.

Re: 12032 - The Monkey and the Oiled Bamboo, WA, Help..

Posted: Sat Feb 21, 2015 8:04 pm
by garbage

Code: Select all

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    vector<long long>v;
	long long n, nxt, fst, T, d, result, last, val;
    
	cin>>T;

    for(long long i=1;i<=T;i++)
    {
        cin>>n;
        
        fst = 0;
        for(long long j=1;j<=n;j++)
        {
            cin>>nxt;
            
            d = nxt - fst;
            fst = nxt;
            v.push_back(d);
        }
        
        sort(v.begin(), v.end());
		
		last = v.size()-1;
		result = v[last];

		for(long long j=result; ;j++)
		{
			val = j;
			bool flag = false;
			for(long long k=last;k>=0;k--)
			{
				if(v[k] > val)
				{
					flag = true;
					break;
				}

				if(v[k] == val)
					val--;
			}

			if(!flag)
			{
				cout<<"Case "<<i<<": "<<j<<endl;
				break;
			}
		}
		v.clear();
    }
    return 0;
}

Re: 12032 - The Monkey and the Oiled Bamboo

Posted: Wed Feb 25, 2015 1:51 am
by brianfry713
Input:

Code: Select all

1
4
3 4 6 7 
AC output 3