ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1607. Taxi

Deadpool Please HELP ME WA 14 // Problem 1607. Taxi 18 Mar 2017 09:29
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>

using namespace std;
int a,b,c,d;
int main()
{
    cin >> a >> b >> c >> d;
    int h = c;
    if(a >= c)
    {
        cout << a;
        return 0;
    }
    while(1)
    {
        if(a == c)
        {
            cout << a;
            return 0;
        }
        a+=b;
        if(c-d >= a) c-=d; else
        {
            if(a > h) cout << h; else
            cout << a;
            return 0;
        }
    }
    return 0;
}