【模拟】Books CodeForces 279B
来源:互联网 发布:淘宝手机营销中心 编辑:程序博客网 时间:2024/05/16 11:53
When Valera has got some free time, he goes to the library to readsome books. Today he's got
Valera decided to choose an arbitrary book withnumber
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 canread.
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;
}
- 【模拟】Books CodeForces 279B
- Permutation CodeForces 359B
- ZZULI 1497 Reading Books
- HDOJ 2101 A + B Problem Too
- hdu 1000 A + B Problem
- fzu 1759 A^B % C
- HDOJ 2075 A|B?
- HDOJ 2034 人见人爱A-B
- HDOJ 2054 A == B ?
- poj 2190 isbn 模拟
- 2057A + B Again
-  
- sum a b
-
- HDOJ 1040 As Easy As A+B
- HDOJ 2503 a/b + c/d
- A + B Problem II
- PAT B 1020. 月饼 (25)
- C++中,get getline gets 用…
- 【线段树】 POJ 2828 Buy Tickets
- 【搜索】优雅的暴力合集
- 【矩阵快速幂】Fibonacci
- 【线段树】敌兵布阵
- 【模拟】Books CodeForces 279B
- 【模拟】Tic-tac-toe C…
- 【图论】A Walk Through…
- Permutation CodeForces 359B
- 【模拟】Cupboard and Balloons
- 九度OJ 1086 清华大学2011年机试 《最小花费》
- android value string.xml %d\% %1$s的用法
- C算法精解 ->集合->实现和分析
- 破解Keil3时出现错误:ERROR R208: RENEW LICENSE ID CODE (LIC)的原因及处理方法