Flawless's blog

By Flawless, 11 years ago, In English

Respected Admin or Anyother coder i submitted this code for problem B. i am getting correct answer for Sample testcase but on codeforces i get "0" for this... i tested for many times and problem still prevails.. Many many advance thanks :)

 #include<iostream>
 #include<cstdio>
 #include<algorithm>
 #define LL long long int
 using namespace std;
 int main()
 {
	LL n,t,i;
	cin>>n>>t;
	LL arr[n];
	for(i=0;i<n;i++)
		cin>>arr[i];
	LL count=0,sum,start,j,ans,temp;
	temp=0;
	start=0;
	count=0;
	for(i=0;i<n;i++)
	{
		sum+=arr[i];
		if(sum<=t)
			temp++;
		else		
		if(sum>t)
		{
			count=max(count,temp);			
			j=start;
			temp++;			
			while(1)
			{							
				sum-=arr[j];
				j++;	
				temp--;
				if(sum<=t)
					break;
				if(j>i)
					break;
							
			}
			start=j;		
		}
			
	}
	count=max(count,temp);
	cout<<count<<endl;
	return 0;
 }
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
11 years ago, # |
Rev. 4   Vote: I like it 0 Vote: I do not like it

Here the testcases that i ran on my g++ compiler shashank@ubuntu:~/Desktop$ ./a.out 4 5 3 1 2 1 3 and here is the codeforces link of my same submission http://codeforces.com/contest/279/submission/3250496

»
11 years ago, # |
Rev. 4   Vote: I like it 0 Vote: I do not like it

You didn't initialize sum variable in line 13. Just write sum=0, and test will be passed.

UPD. Checked with this change, solution got AC.