When Valera has got some free time, he goes to the library to read
some books. Today he's got
Valera decided to choose an arbitrary book with
number
Print the maximum number of books Valera can read.
The first line contains two integers
Print a single integer — the maximum number of books Valera can read.
4 5
3 1 2 1
3
3 3
2 2 3
1
#include
#include
using namespace std;
long long
int main()
{
int n;
long long t;
scanf("%d %I64d", &n, &t);
for (int i = 1; i <= n; i++)
scanf("%I64d", &a[i]);
long long now = 0;
int nown = 0;
int max = 0;
int r = n;
for (int l = n; l > 0; l--)
{
now += a[l];
nown++;
if (now <= t)
{
if (nown > max) max = nown;
}
else
while (now > t && r>0)//注意while语句都要判断边界,尽管自己觉得不会有问题,但是什么奇葩的数据都有。。。
{
now -= a[r];
nown--;
r--;
}
}
printf("%d\n", max);
return 0;
}