【Codeforces】1215A. Yellow Cards

题目描述

The final match of the Berland Football Cup has been held recently. The referee has shown nn yellow cards throughout the match. At the beginning of the match there were a1a1 players in the first team and a2a2 players in the second team.

The rules of sending players off the game are a bit different in Berland football. If a player from the first team receives k1k1 yellow cards throughout the match, he can no longer participate in the match — he’s sent off. And if a player from the second team receives k2k2 yellow cards, he’s sent off. After a player leaves the match, he can no longer receive any yellow cards. Each of nn yellow cards was shown to exactly one player. Even if all players from one team (or even from both teams) leave the match, the game still continues.

The referee has lost his records on who has received each yellow card. Help him to determine the minimum and the maximum number of players that could have been thrown out of the game.

Input

The first line contains one integer a1a1 (1≤a1≤1000)(1≤a1≤1000) — the number of players in the first team.

The second line contains one integer a2a2 (1≤a2≤1000)(1≤a2≤1000) — the number of players in the second team.

The third line contains one integer k1k1 (1≤k1≤1000)(1≤k1≤1000) — the maximum number of yellow cards a player from the first team can receive (after receiving that many yellow cards, he leaves the game).

The fourth line contains one integer k2k2 (1≤k2≤1000)(1≤k2≤1000) — the maximum number of yellow cards a player from the second team can receive (after receiving that many yellow cards, he leaves the game).

The fifth line contains one integer nn (1≤n≤a1⋅k1+a2⋅k2)(1≤n≤a1⋅k1+a2⋅k2) — the number of yellow cards that have been shown during the match.

Output

Print two integers — the minimum and the maximum number of players that could have been thrown out of the game.

Examples

input
2
3
5
1
8
output
0 4
input
3
1
6
7
25
output
4 4
input
6
4
9
10
89
output
5 9

Note

In the first example it could be possible that no player left the game, so the first number in the output is 00. The maximum possible number of players that could have been forced to leave the game is 44 — one player from the first team, and three players from the second.

In the second example the maximum possible number of yellow cards has been shown (3⋅6+1⋅7=25)(3⋅6+1⋅7=25), so in any case all players were sent off.

题解

题意

有两支队伍,人数为a1,a2;

第一支队伍,每个队员得到k1张黄牌才能被罚下场;

第二支队伍,每个队员得到k2张黄牌才能被罚下场;

裁判一共给出n张黄牌,问最少下场多少人,最多下场多少人。

思路

最少下场:

每个人获得(k1-1)、(k2-1)张黄牌,得出无人下场时最多接受的黄牌数量m=(k1-1)*a1+(k2-1)*a2;

当n>m时,(n-m)即为最少下场人数;

当n<=m时,最少下场人数为0。

最多下场:

比较k1和k2,从k小的开始罚起,将k小的存入a1和k1中;

若a1*k1>=n,则最多下场人数为n/k1;

若a1k1<n,则最多下场人数为a1+(n-a1k1)/k2。

代码

#include<iostream>
using namespace std;

int main()
{
    int a1,a2,k1,k2,n;
    cin>>a1>>a2>>k1>>k2>>n;
    int min,max;
    int m=a1*(k1-1)+a2*(k2-1);
    if(n<=m)
        min=0;
    else
        min=n-m;
    if(k1>k2){
        swap(k1,k2);
        swap(a1,a2);
    }
    if(a1*k1<n)
    	max=a1+(n-a1*k1)/k2;
    else
        max=n/k1;
    cout<<min<<' '<<max<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值