Chunga-Changa(CodeForces-1181A)

A. Chunga-Changa
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called “chizhik”. One has to pay in chizhiks to buy a coconut now.

Sasha and Masha are about to buy some coconuts which are sold at price zz chizhiks per coconut. Sasha has xx chizhiks, Masha has yy chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.

The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can’t be split in parts, so the girls can only exchange with integer number of chizhiks.

Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be33 chizhiks. If the girls don’t exchange with chizhiks, they will buy 1+1=2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2+1=3 coconuts.

It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).

Input
The first line contains three integers x, y and z (0≤x,y≤1018, 1≤z≤1018) — the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.

Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.

Examples
inputCopy
5 4 3
outputCopy
3 1
inputCopy
6 8 2
outputCopy
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3+4=7 coconuts.
题意:Sasha有x元,Masha有y元,一个椰子z元,一个女孩可以给另一个女孩一些钱,来增加买的椰子的数量,给定x,y,z,打印两个整数:一个女孩能买到椰子的最大数量和一个女孩必须给另一个女孩的椰子的最小数量。
思路:一个女孩能买到的最大数量就是(x+y)/z,把所有的钱都聚在一起就是一个人可以买到的最大数量,然后给对方的最小数量就是有两种情况
(1)x%z是x最多买椰子后剩下的钱,y%z是y最多买椰子后剩下的钱,如果x%z+y%z两个人剩下的钱聚在一起>=z,就代表可以买多余的椰子,把多的钱聚在一起给到一个人身上,因为打印最小数量就看x%z和y%z谁小,就谁给钱,聚到另一个人身上
(2)如果x%z+y%z<z,就代表把多的钱都不能买一个椰子,所以谁给钱都没用,就是自己买自己的数量就是最大的
(3)如果有一个人没有剩下钱,就代表不用给对方钱,每个人现在的都是最大的情况,因为已经可以整除,所以如果给别人,自己就不能得到最大的了,所以不用给别人钱

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
int main ()
{
    ll x,y,z;
    scanf("%lld %lld %lld",&x,&y,&z);
    printf("%lld ",(x+y)/z);//一个人最大可以买的数量
    ll d1=x%z;
    ll d2=y%z;
    if(d1==0||d2==0||d1+d2<z){//整除或钱不够
        printf("0\n");
    }
    else{//钱够的话
        if(z-d1<z-d2)
        printf("%lld\n",z-d1);//看谁小就谁给钱
        else
        printf("%lld\n",z-d2);
    }
    return 0;
}
/*
x y z
5 4 3
2 1 
3 1
6 3
2+1=3
6 8 2
3+4=7
7 0
*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值