codeforces 846/B Math Show(思维)

B. Math Show
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.

By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.

Polycarp has M minutes of time. What is the maximum number of points he can earn?

Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).

The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.

Output
Print the maximum amount of points Polycarp can earn in M minutes.

Examples
input
3 4 11
1 2 3 4
output
6
input
5 5 10
1 2 4 8 16
output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.

In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
const int MAX = 1e6+10;
int a[MAX];

int main() 
{
    int n, k, t;
    int sum, Max;
    while (~scanf("%d%d%d",&n,&k,&t)) 
    {
        sum = 0;
        for (int i = 0; i < k; i++) 
        {
            scanf("%d",&a[i]);
            sum += a[i];
        }
        Max = 0;
        sort(a, a + k);
        for (int i = 0; i <= n; i++) 
        {
            int ans = t - i*sum;
            if (ans < 0) 
            {
                break;
            }
            int cnt = k * i + i;
            for (int j = 0; j < k; j++) 
            {
                if (ans >= a[j] * (n - i)) 
                {
                    cnt += (n - i);
                    ans -= (n - i)*a[j];
                }
                else 
                {
                    cnt += (ans / a[j]);
                    break;
                }
            }
            Max = max(Max, cnt);
        }
        cout << Max << endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值