A. Chunga-Changa

题目链接:http://codeforces.com/contest/1181/problem/A

题目

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≤10^18, 1≤z≤10^18) — 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
5 4 3

Output

3 1

Input

6 8 2

Output

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.

题意

两个人各有一定数量的钱,求在两个人的钱混合在一起能买多少个物品和其中一个人要给另一个人最小的钱数来买到这么多物品。
 

思路

两人钱数相加除以单价即为购买物品个数,每个人的钱数模单价减去单价的绝对值即为其中一个人要给另一个人的钱数。
 
 
//
// Created by hjy on 19-6-5.
//
#include<bits/stdc++.h> using namespace std;
const int maxn = 2e5 + ;
typedef long long ll;
int main()
{
ll a,b,c;
while(cin>>a>>b>>c)
{
ll result=(a+b)/c;
if((a/c)+(b/c)==result)
cout<<result<<' '<<<<endl;
else
{
//cout<<a%c<<' '<<b%c<<endl;
cout<<result<<' '<<min(abs(a%c-c),abs(b%c-c))<<endl;
}
}
return ;
}

Codeforces Round #567 (Div. 2)A的更多相关文章

  1. Codeforces Round #567 (Div. 2) E2 A Story of One Country (Hard)

    https://codeforces.com/contest/1181/problem/E2 想到了划分的方法跟题解一样,但是没理清楚复杂度,很难受. 看了题解觉得很有道理,还是自己太菜了. 然后直接 ...

  2. Codeforces Round #567 (Div. 2)B. Split a Number (字符串,贪心)

    B. Split a Number time limit per test2 seconds memory limit per test512 megabytes inputstandard inpu ...

  3. Codeforces Round #567 Div. 2

    A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000010 ...

  4. Codeforces Round #567 (Div. 2)自闭记

    嘿嘿嘿,第一篇文章,感觉代码可以缩起来简直不要太爽 打个div2发挥都这么差... 平均一题fail一次,还调不出错,自闭了 又一次跳A开B,又一次B傻逼错误调不出来 罚时上天,E还傻逼了..本来这场 ...

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

    原文链接:传送 #include"algorithm" #include"iostream" #include"cmath" using n ...

  6. Codeforces Round #567 (Div. 2) B. Split a Number

    Split a Number time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  7. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. Chrome浏览器离线安装 Postman 5.X 报错

    下载和安装请参考 博友文章http://www.cnblogs.com/wangfeng520/p/5892125.html 尝试安装此扩展程序时出现以下警告: Ignored insecure CS ...

  2. python 教程 第十三章、 特殊的方法

    第十三章. 特殊的方法 1)    特殊的方法 __init__(self,...) 这个方法在新建对象恰好要被返回使用之前被调用. __del__(self) 恰好在对象要被删除之前调用. __st ...

  3. C#实现进程内存信息获取

    using System.Collections.Generic;using System.Runtime.InteropServices;using System;using System.Diag ...

  4. Apache 配置两个域名匹配的文件夹和配置多个Web站点

    Apache的虚拟主机是一种同意在同一台机器上,执行超过一个站点的解决方式,同一时候也就能够邦迪二级域名到指定的文件夹.虚拟主机有两种.一种叫基于IP的(IP-based),还有一种叫基于名字的(na ...

  5. vagrant up default: Warning: Authentication failure. Retrying...的一些解决办法

    vagrant up default: Warning: Authentication failure. Retrying...的一些解决办法 一般看到这个信息时,虚拟机已经启动成功,可以中断命令后v ...

  6. Win8 Metro(C#)数字图像处理--2.55OSTU法图像二值化

    原文:Win8 Metro(C#)数字图像处理--2.55OSTU法图像二值化  [函数名称] Ostu法图像二值化      WriteableBitmap OstuThSegment(Writ ...

  7. 微信小程序把玩(十三)progress组件

    原文:微信小程序把玩(十三)progress组件 进度条描述的是一种加载的状态,比如软件升级下载进度, 视频,图片下载进度- 主要属性: wxml <progress percent=" ...

  8. PHP 的魔术方法及其应用

    PHP中将所有__(两个下划线)开头的类方法作为魔术方法,这方法之所以称为魔术方法是因为其实现的功能就如变魔术一样感觉很神奇.在特定的事件下触发,这真的很酷. **__construct()** 这个 ...

  9. 求 1-2+3-4+5-6+7-8....M 的结果算法

    static void Main(string[] args) { /** * 算法题: * 求 1-2+3-4+5-6+7-8....M 的结果. * */ //存储运算结果. ; //记号. ; ...

  10. 网络文件系统nfs文件系统使用(很全面)

    一.NFS简介 1.NFS就是Network FileSystem的缩写,它的最大功能就是可以通过网络让不同的机器,不同的操作系统彼此共享文件(sharefiles)——可以通过NFS挂载远程主机的目 ...