CF 397 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 ka and b (1 ≤ k ≤ 1090 ≤ a, b ≤ 109a + 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.



题意:

Misha and Vanya进行了桌球比赛,每场比赛都是由好几场小比赛组成的,每个小比赛赢加1分,输不加分,然后有一个人得了k分就赢得这场比赛,所有比分归零。开始下一场比赛。现在给你三个整数,k(得k分赢一场),a(Misha 所有比赛累积下来的总分),b(Vanya所有比赛累积下来的总分)。问你最多可以组成几场比赛,如果不能组成完整的比赛输出-1,不然输出最大得场数。

注意!!!每组数据都是完整的比赛!!!!!!!(之前没看到这个被人Hack一发,TVT)



题解:

你会发现如果要是完整得比赛的话,如果某个人对k取模有余数的话,对手必需赢过至少一场的话,才能和余数组成一场完整的比赛,不然的话余数无论如何也不能被消耗掉。就是-1呗。其他的话是输出a/k+b/k就可以了。


#include <iostream>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
	long long k,a,b;

		cin>>k>>a>>b;
		long long num1 = a/k;
		long long num3 = a%k;
		long long num2 = b/k;
		long long num4 = b%k;
		long long num = num1+num2;
		if((num2==0 && num3!=0) || (num1==0 && num4!=0))
			cout<<"-1"<<endl;
		else
			cout<<num<<endl;
	
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值