Educational Codeforces Round 28 B: Math Show


Math Show

Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered1 throughk. It takes himtj minutes to solve thej-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 Polycarpcompletely 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 isk + 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, valuestj (1 ≤ tj ≤ 1000000), wheretj is the time in minutes required to solvej-th subtask of any task.

Output

Print the maximum amount of points Polycarp can earn inM minutes.




       题意:  给定你 n 个相同任务, 每个包含 k  个小任务,从1 到 k ,  n 个相同任务 的 完成时间相同, 但每个小任务的完成时间不相同。 当你完成了一个大的任务之后,ans 在原来的基础上加1 ; 让你求 max  ->  ans;


       思路:  本来考虑是 dp 的,然而不会dp ,就想着用贪心求,考虑模拟得到最优的方式吧。

首先枚举   可以完成  i  个大的任务, 然后循环找到从 时间到最大的, 其实就是暴力求解,数据不大。

注意  爆 int  问题。




 

#include
using namespace std;

typedef long long ll;

ll A[100];
ll n,k,m;
int main()
{
    while(scanf("%lld%lld%lld",&n,&k,&m)!=EOF)
    {
        ll sum=0;
        for(int i=1;i<=k;++i)
        {
            scanf("%lld",&A[i]);
            sum+=A[i];
        }
        sort(A+1,A+k+1);
        ll ans=0;
        for (int i=0;i<=n && m>=i*sum;++i)
        {
            ll tot=i*(k+1),tem=m-i*sum;
            for(int j=1;j=A[j])
                    {
                        tem-=A[j];
                        tot++;
                    }
            ans=max(ans,tot);
        }
        printf("%lld\n",ans);
    }
    return 0;
}

 

你可能感兴趣的:(codeforse)