You are not logged in. Please login at www.codechef.com to post your questions!

×

Different Output

Today,there was a coding round for internship in our collage.I wrote a code which was giving different output for same test case on ideone and Hackerrank.On ideone output was 4 and on hackerrank output
 was 0.I don't why??can anyone explain.
here is that test case and  my code ...
4 1
2
3
5
7


#include <iostream>
using namespace std;
int main() {
        int s,g;
        cin>>s>>g;
        int arr[s];
        int c=g;
        for(int i=0;i<s;i++)
        cin>>arr[i];
        int len=1;
        int val=0;
        for(int i=1;i<s;i++)
        {
            if(arr[i]==arr[i-1]+1)
            len++;
            else if(arr[i]-arr[i-1]<=g+1)
            {
                len+=(arr[i]-arr[i-1]);
                g=g-(arr[i]-arr[i-1]);
            }
            else
            {
                if(val<len)
                val=len;
                len=1;
                //g=c;
            }
        }
        if(val<len)
        val=len;
            cout<<val<<endl;
    return 0;

}

asked 08 Mar '14, 00:02

raj01104's gravatar image

2★raj01104
2452410
accept rate: 0%

edited 08 Mar '14, 00:03

It was a close contest so i don't have problem statement :(

(08 Mar '14, 22:28) raj011042★

link for the problem?

link

answered 08 Mar '14, 06:37

garakchy's gravatar image

1★garakchy
1.1k163048
accept rate: 1%

Question please...:)

link

answered 08 Mar '14, 10:11

bipin2's gravatar image

3★bipin2
3.1k254671
accept rate: 8%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×164

question asked: 08 Mar '14, 00:02

question was seen: 681 times

last updated: 08 Mar '14, 22:28