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. 不使用运算符(+、-、*、/) 来进行四则运算(C#)

    最近在LeetCode 上刷题,遇到一个非常有趣的题目,题目的大概意思就是在不使用运算符的情况下实现两个数的加法...原题点这里>>> 说实话,刚看到这题目,我是一脸懵逼的. 后来仔 ...

  2. aspnetboilerplate && .net core 使用原生sql

    利用aspnetboilerplate提供的工具类IDbContextProvider private readonly IDbContextProvider<XXXDbContext> ...

  3. 【转载】json 数据 添加 删除 排序

    张映 发表于 2014-02-10 分类目录: js/jquery 标签:json, 删除, 排序, 添加 js数据格式和json数据格式,各有各的用处,就个人而言,json更好用一点,js自身的数组 ...

  4. 属性更改通知(INotifyPropertyChanged)——针对ObservableCollection

    问题 在开发webform中,wpf中的ObservableCollection<T>,MSDN中说,在添加项,移除项时此集合通知控件,我们知道对一个集合的操作是CURD但是恰恰没有Upd ...

  5. WPF x:static的使用

    <Window x:Class="XamlTest.Window1"        xmlns="http://schemas.microsoft.com/winf ...

  6. WPF 视图导航

    <Window x:Class="ViewExam.MainWindow"        xmlns="http://schemas.microsoft.com/w ...

  7. 【全面解禁!真正的Expression Blend实战开发技巧】十一章 全面解析布局(Grid & Canvas &StackPanel &Wrappanel)

    原文:[全面解禁!真正的Expression Blend实战开发技巧]十一章 全面解析布局(Grid & Canvas &StackPanel &Wrappanel) 写这篇文 ...

  8. Qt 5.9对Mac的图形显示有许多改进

    We have some platform specific improvements as well as support for new platforms and compilers comin ...

  9. foreach获取索引值

    List<" }; foreach (string item in items) { int index = items.IndexOf(item); Console.WriteLin ...

  10. Android疑难杂症之Theme

    背景:最近在把自己之前写的一个应用换成Material Design风格,在看官方Guide后动手试了一试,没想到出门就遇到了坑,在换成Material Design风格的主题后,我设置了一下colo ...