Codeforces and Polygon may be unavailable from December 6, 19:00 (UTC) to December 6, 21:00 (UTC) due to technical maintenance. ×

Flawless's blog

By Flawless, 12 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

»
12 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://mirror.codeforces.com/contest/279/submission/3250496

»
12 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.