CodeForces

来源:互联网 发布:如何查看已占用的端口 编辑:程序博客网 时间:2024/06/07 05:34

题目链接:http://codeforces.com/problemset/problem/417/A点击打开链接

A. Elimination
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.

The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems. The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination.

As a result of all elimination rounds at least n·m people should go to the finals. You need to organize elimination rounds in such a way, that at least n·m people go to the finals, and the total amount of used problems in all rounds is as small as possible.

Input

The first line contains two integers c and d (1 ≤ c, d ≤ 100) — the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≤ n, m ≤ 100). Finally, the third line contains an integer k(1 ≤ k ≤ 100) — the number of the pre-chosen winners. 

Output

In the first line, print a single integer — the minimum number of problems the jury needs to prepare.

Examples
input
1 107 21
output
2
input
2 22 12
output
0


#include <iostream>#include <algorithm>#include <cstring>#include <vector>#include <stdio.h>#include <string.h>using namespace std;struct xjy{    int weight;    int val;};vector < xjy > s;int main(){    int c,d,n,m,k;    cin >> c >> d;    cin >> n >> m;    cin >> k;    int num=n*m-k;    xjy mid;    mid.val=1;    mid.weight=d;    s.push_back(mid);    mid.val=n;    mid.weight=c;    s.push_back(mid);    int maxn=n*m*d;    int dp[maxn+5];    memset(dp,0,sizeof(dp));    for(int i=0;i<s.size();i++)        for(int j=s[i].weight;j<=maxn;j++)            dp[j]=max(dp[j],dp[j-s[i].weight]+s[i].val);    int ans=maxn;    for(int i=1;i<=maxn;i++)        if(dp[i]>=num)        {            ans=i;            break;        }    if(num<=0)        ans=0;    cout << ans;}





原创粉丝点击