Ural 1430. Crime and Punishment

1430. Crime and Punishment

Time limit: 0.5 second
Memory limit: 64 MB

Background

Petty bureaucrat Victor Thiefton was disposed towards stealing from his childhood. But one thing is to legally privatize national factories, diamond fields and oil derricks at the cost of billions dollars. And another thing is to filch some money from a poor regional budget. Our legislation is very strict. Therefore Victor felt that justice is on the alert just after he extracted his hand from the national pocket. What should he do to escape inevitable punishment?
Mr. Thiefton has once heard that in accordance with the criminal legislation standards he would be condemned to long imprisonment for a theft whereas in case of a peculation he could escape with a suspended sentence only. So if the most part of stolen money is peculated, the duration of imprisonment will be reduced.

Problem

The same evening Mr. Thiefton burst into "MegaApril" superstore and rushed for overflowing storefronts carrying a purse with N stolen dollars. It appeared that unlimited number of high-quality goods and goods at moderate price were on sale in the superstore. High-quality goods cost A dollars per piece, and goods at moderate price cost B dollars per piece. Victor should spend as much stolen money as possible to reduce the duration of imprisonment to a minimum.

Input

The only line contains the integer numbers A, B and N (1 ≤ A, B, N ≤ 2∙10 9).

Output

You should output the number of high-quality goods and the number of goods at moderate price, which should be bought to guarantee the minimal duration of imprisonment for Victor. The numbers should be separated by single space. If the problem has several solutions, you should output any of them.

Sample

input output
8 5 22
2 1
Problem Author: Nikita Rybak, Ilya Grebnov, Dmitry Kovalioff
Problem Source: Timus Top Coders: First Challenge
用n元买价值分别为a,b的东西,要使剩余的钱最少。
暴力就能过
#include<iostream>
using namespace std;
#define MIN 0x7fffffff
long long  a,b,n,t,x,d,i;
bool flag;
int main()
{
    cin>>a>>b>>n;
    x=0;
    if (a < b)
    {
        swap(a,b);
        flag=true;
    }
    t=min(n/a,b);
    d=MIN;
    for (i=0; i<=t; i++)
        if ((n-a*i)%b < d)
        {
            d=(n-a*i)%b;
            x=i;
        }
    if (!flag)
        cout << x << ' ' << (n-a*x)/b << endl;
    else
        cout << (n-a*x)/b << ' ' << x << endl;
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值