CodeForces 35 D.Animals(贪心)

Description

n天,每天会来一种动物,第i天来的动物一天要吃ci吨食物,一个动物来了之后就一直吃到第n天,总共只有x吨食物,问食物最多可以供多少只动物吃

Input

第一行两个整数nx分别表示天数和食物总数,之后n个整数ci表示第i天来的动物的食量(1n100,1x104,1ci300)

Output

输出最多可以供多少动物吃

Sample Input

3 4

1 1 1

Sample Output

2

Solution

贪心,第i天来的动物会吃ci×(n+1i)吨食物,对这个值排序后从小往大选即可

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=100001;
int n,x,c[maxn];
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    while(~scanf("%d%d",&n,&x))
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&c[i]),c[i]*=(n-i+1);
        sort(c+1,c+n+1);
        int sum=0,i=1;
        while(i<=n&&sum+c[i]<=x)sum+=c[i],i++;
        printf("%d\n",i-1);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值