Codeforces--279B--Books

题目描述:
When Valera has got some free time, he goes to the library to read some books. Today he’s got t free minutes to read. That’s why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let’s number the books by integers from 1 to n. Valera needs ai minutes to read the i-th book.
Valera decided to choose an arbitrary book with number i and read the books one by one, starting from this book. In other words, he will first read book number i, then book number i + 1, then book number i + 2 and so on. He continues the process until he either runs out of the free time or finishes reading the n-th book. Valera reads each book up to the end, that is, he doesn’t start reading the book if he doesn’t have enough free time to finish reading it.
Print the maximum number of books Valera can read.
输入描述:
The first line contains two integers n and t (1 ≤ n ≤ 105; 1 ≤ t ≤ 109) — the number of books and the number of free minutes Valera’s got. The second line contains a sequence of n integers a1, a2, …, an (1 ≤ ai ≤ 104), where number ai shows the number of minutes that the boy needs to read the i-th book.
输出描述:
Print a single integer — the maximum number of books Valera can read.
输入:
4 5
3 1 2 1
3 3
2 2 3
输出:
3
1
题意:
看书,给出n本书,编号1到n,和看每本书需要的时间,他看书是随机的,然后是连续的,从第 i 本开始看,看完了会看第i+1本,然后是第i+2本,问他在时间 t 内最多能看多少本书。
题解
直接搞
代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

struct point{
    int x,y,z;
};

point a[105];

int cmp(point a,point b){
    if(a.y == b.y) return a.z < b.z;
    return a.y > b.y;
}

int main(){
    int n,k;
    while(scanf("%d%d",&n,&k)!=EOF){
        int ans = 0;
        int xx,yy;
        for(int i = 1; i <= n; i ++){
            scanf("%d%d",&xx,&yy);
            a[i].x = i;
            a[i].y = xx;
            a[i].z = yy;
        }
        sort(a + 1,a + n + 1,cmp);
        int c1 = a[k].y,c2 = a[k].z;
        for(int i = 1; i <= n; i ++){
            if(a[i].y == c1 && a[i].z == c2) ans ++;
        }
        printf("%d\n",ans);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值