Codeforces Round #567 (Div. 2) A. Chunga-Changa

time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard 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 z

chizhiks per coconut. Sasha has x chizhiks, Masha has y

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 be 3 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

Input

Copy

(copy)

5 4 3

Output

Copy

(copy)

3 1

Input

Copy

(copy)

6 8 2

Output

Copy

(copy)

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.

思路:如果x%z+y%z<z 直接输出x/z+y/z 借款金额为0;否则输出x/z+y/z+1  借款金额就是哪个剩的钱多,另一个借给他,钱数就是z减大的余数

#include <cstdio>
#include<math.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
int main()
{
    ll x,y,z;
    cin>>x>>y>>z;
    ll sum=0,s,x1,y1;
    sum=x/z+y/z;
    x1=x%z;y1=y%z;
    if(x1+y1<z)
    {
        cout<<sum<<" 0"<<'\n';
    }
    else
    {
        if(x1>y1)
        {
            s=z-x1;
        }
        else s=z-y1;
        sum++;
        cout<<sum<<" "<<s<<'\n';
    }
}

 

全部评论

相关推荐

Yki_:你要算时间成本呀,研究生两三年,博士三四年,加起来就五六年了,如果你本科去腾讯干五年,多领五年的年薪,加上公司内涨薪,可能到时候十五年总薪资也跟博士差不多
点赞 评论 收藏
分享
05-25 10:45
门头沟学院 Java
Frank_zhang:没实习一个项目肯定不够,可以再做一个轮子,技术栈再补一个mq,微服务,整体再换个简历模板,暑期尽量再找一个日常实习
点赞 评论 收藏
分享
我的人生算是废了,23届裸辞空档一年,存款只能坚持几个月了,找不到像样的工作了,人生何去何从。
梦想是成为七海千秋:这大环境下为什么要裸辞呀,风险真的挺大的,而且社招的话23届没有太多的竞争力,不过既然已经裸辞了就不要焦虑慢慢找。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务