codeforces 846B 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

题意:有n个任务,每个都有k个子任务,完成第kj个子任务的时间为 ti,完成一个子任务得一分,而且完成了一个大任务则多得一分,

枚举加暴力:枚举完成了几个大任务,然后其他的都是子任务,子任务按时间从小到大完成就行。

#include 
#include
#include
#include
#include
const int maxn = 50;
typedef long long ll;
using namespace std;
ll n,k,M;
int a[maxn+5],b[maxn*maxn];
void ok()
{
    ll ans=0,cot=0,tot=0,cnt=0,sum=0;
    sort(a+1,a+k+1);
    for(int i=1;i<=k;i++) cot+=a[i];
    for(int i=0;i<=n;i++)
    {
        tot = cot*i;
        if(tot>M) break;
        sum = tot , cnt = (k+1)*i;
        for(int j=1;j<=k;j++)
        {
            for(int r=i+1;r<=n;r++){
                sum+=a[j];
                cnt++;
                if(sum>M){
                    cnt--, j = k+1;
                    break;
                }
            }
        }
        ans = max(ans,cnt);
    }
    printf("%I64d\n",ans);
}
int main()
{
    while(~scanf("%I64d %I64d %I64d",&n,&k,&M))
    {
        for(int i=1; i<=k; i++) scanf("%d",&a[i]);
        ok();
    }
    return 0;
}


你可能感兴趣的:(codeforce,######,其他,######)