[CF846B]Math Show题解

暴力一下就好啦!
枚举一下一共做多少次任务,剩下的时间将子任务排序,从头开始能取多少取多少就行了。

贴个代码

#include <cstdio>
#include <algorithm>
#define ll long long

using namespace std;

inline ll read(){
    ll x = 0; int zf = 1; char ch = ' ';
    while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    if (ch == '-') zf = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}

ll cost[50];

ll tot = 0;

int main(){
    int n = read(), k = read(), M = read();
    for (int i = 1; i <= k; ++i)
        cost[i] = read(), tot += cost[i];
    sort(cost + 1, cost + k + 1);
    long long cur, ans = 0, left;
    for (int i = 0; i <= n; ++i){
        if (M - tot * i < 0)
            break;
        left = M - tot * i;
        cur = i * (k + 1);
        for (int j = 1; j <= k; ++j){
            for (int k = 1; k <= (n - i); ++k){
                if (left - cost[j] >= 0)
                    left -= cost[j], ++cur;
                else
                    break;
            }
        }
        if (cur > ans)  
            ans = cur;
    }
    printf("%lld", ans);
    return 0;
}

转载于:https://www.cnblogs.com/linzhengmin/p/10861591.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值