Horse Racing Duals puzzle discussion


I did it in Python. For some reason I pass "Horses in any order" and "Many horses", but not "Simple case". It seems like first input is entering 3 instead of 4, so it prints when I inserted

print('n = ' + str(n), file=sys.stderr)


n = int(input())


The problem statement doesn't say that all the speeds you'll be given are unique, which implies that there is a chance that horses with the same speed will be in the data set. What will be the result if those horses race each other, and what will the difference in speeds be?

From another perspective, the output D is shown to be an integer value greater than or equal to zero. Can your algorithm produce that?


Hello, I made this code :
include iostream>
include string>
include vector>
include algorithm>
include set>

using namespace std;

int main(){
set<unsigned long> myset;

unsigned int N;
cin >> N; cin.ignore();
for (unsigned int i = 0; i < N; i++) {
    unsigned long Pi;
    cin >> Pi; cin.ignore();


set<unsigned long>::iterator it=myset.end();

unsigned long ecartTmp=*it-*--it;

if (ecartTmp==1 || myset.size()==2){
    cout << ecartTmp <<endl;
    return 0;

unsigned long ecart=ecartTmp;


    if (ecartTmp==1){
        cout << "1" <<endl;
        return 0;

    if (ecartTmp<ecart){

cout << ecart << endl;

// Write an action using cout. DON'T FORGET THE "<< endl"
// To debug: cerr << "Debug messages..." << endl;

It pass "horses in desorder" in IDE but not when I submitted it, why?

Thanks for help :blush:


My code gets 90% on validation test. It does not print the values for the shorter distance among the initial two horses according to the results. I don know why.

 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
let arr = []
let arr2 = []

var N = parseInt(readline());
for (var i = 0; i < N; i++) {
    var pi = parseInt(readline());
arr = arr.sort()
for(let i = 1;i<arr.length;i++){

for(let i =0;i<arr2.length;i++){
        arr2[i] = arr2[i]*-1}}
arr3 = arr2.reduce(function(p,n){if(p>n){return n}
else{return p}})

Here is my code. It would be great if you could help me.