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

Why test # 6 is wrong?
Posted by AlexRad 22 Mar 2015 14:34
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var tokens = Console.ReadLine().Trim().
                Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

            var a = int.Parse(tokens[0]);
            var b = int.Parse(tokens[1]);
            var c = int.Parse(tokens[2]);
            var d = int.Parse(tokens[3]);

            var min = a + (c - a) / (b + d) * b;
            var max = c - (c - a) / (b + d) * d;

            min = Math.Min(min + b, Math.Max(min, max));
            max = Math.Max(max - d, min);

            Console.WriteLine(max);
Re: Why test # 6 is wrong?
Posted by AlexRad 22 Mar 2015 14:51
Corrected, see !!! sign

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var tokens = Console.ReadLine().Trim().
                Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

            var a = int.Parse(tokens[0]);
            var b = int.Parse(tokens[1]);
            var c = Math.Max(int.Parse(tokens[2]), a); // !!!!
            var d = int.Parse(tokens[3]);

            var min = a + (c - a) / (b + d) * b;
            var max = c - (c - a) / (b + d) * d;

            min = Math.Min(min + b, max);
            max = Math.Max(max - d, min);

            Console.WriteLine(max);
        }
Re: Why test # 6 is wrong?
Posted by Ionkin M [Samara SAU #617] 29 Mar 2017 02:08
This is strange: "The driver would not ask a sum that is less than that offered by Petr."
Re: Why test # 6 is wrong?
Posted by avro01 14 Sep 2020 18:26
#include<bits/stdc++.h>

using namespace std;

int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}


int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int carry=(c-a)%(b+d);
    int res=(c-a)/(b+d);
    if(carry==0){
        cout<<a+res*b<<'\n';
    }
    else if(carry>=b){
        cout<<a+(res+1)*b<<'\n';
    }
    else if(carry<b){
        cout<<c-res*d<<'\n';
    }
}



why wrong ans in test #6?