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;
}
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.net/contest/279/submission/3250496
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.
Thanks a lot brother, one silly mistake took me down !!
In future, to debug you can run your program online on CodeForce http://codeforces.net/problemset/customtest