【Codeforces 765 C. Table Tennis Game 2】+ 贪心

C. Table Tennis Game 2
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.

Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.

Note that the game consisted of several complete sets.
Input

The first line contains three space-separated integers k, a and b (1 ≤ k ≤ 109, 0 ≤ a, b ≤ 109, a + b > 0).
Output

If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input

11 11 5

Output

1

Input

11 2 3

Output

-1

Note

Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of “balance” (the winning player has to be at least two points ahead to win a set) has no power within the present problem.

乒乓球赛,其中一方达到k分,分数清零后重新开始下一场,给出两个人比赛了n场后的最终总得分a,b,最多比赛了多少场,若给出的a,b不合法输出-1

AC代码:

#include<cstdio>
int main()
{
    int k,a,b;
    scanf("%d %d %d",&k,&a,&b);
    printf((a % k && b / k == 0) || (b % k && a / k == 0) ? "-1\n" : "%d\n",a / k + b / k);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值