Codeforces functionality may be limited from June 18, 19:00 (UTC) to June 19, 3:00 AM (UTC) due to technical maintenance. Polygon will work as usual. ×

The code runs fine on my machine but fails to give the right answer in codeforces

Revision en2, by CodeRazer, 2021-08-13 00:07:30

The following code gives the correct result on my machine, but doesn't give the right answer on codeforces. 125707404 any help will be be appreciated

#include <stdio.h>
#include <stdlib.h>
 
int comparator (const void * p1, const void * p2)
{
  return (*(double*)p1 - *(double*)p2);
}
 
double maxx(double a, double b) {
    if (a > b){
        return a;
    }
    else{
        return b;
    }
}
 
int main() {
    int n;
    double l;
    scanf("%d %lf", &n, &l);
    double a[n+1];
    for (int i = 0; i<n; ++i) {
        scanf("%lf", &a[i]);
    }
    qsort(a, n, sizeof(double), comparator);
    double maxdiff = 0;
    double prev = a[0];
    maxdiff = (a[0] - 0)*2;
    for (int i = 1; i<n; ++i){
        maxdiff = maxx(maxdiff, a[i] - prev);
        prev = a[i];
    }
    maxdiff = maxx(maxdiff, l*2 - prev*2);
    double ans;
    ans = maxdiff/2;
 
    printf("%lf\n", ans);
    return 0;
}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English CodeRazer 2021-08-13 00:07:30 812 Tiny change: 'd\n\n~~~~~C\n#include' -> 'd\n\n~~~~~\n#include'
en1 English CodeRazer 2021-08-13 00:06:31 245 Initial revision (published)