Need help with codeforces "Vanya and lanterns"

So here’s the link to the question. Problem - B - Codeforces

Here is my solution: Submission #74751893 - Codeforces

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define debug(var) cout << #var << ": " << var << "\n"
#define SORTV(vec) sort((vec).begin(), (vec).end())

void solve() {
    int n, l; cin >> n >> l;  // number of lanterns and length of road
    vector<int> lights(n);
    for (int i = 0; i < n; ++i) {
        cin >> lights[i];
    int maxDist = 2*max(lights[0], l-lights[n-1]);
    for (int i = 0; i < n-1; ++i) {
        maxDist = max(maxDist, lights[i+1]-lights[i]);
    cout << maxDist/(double)2;

int main() {

Here’s the solution given in the editorial

#include <stdio.h>
#include <algorithm>
using namespace std;
int n,i,a[100500],rez,l;
int main()
    for (i = 0; i < n; i++)
    rez = 2*max(a[0],l-a[n-1]);
    for (i = 0; i < n-1; i++)
        rez = max(rez, a[i+1]-a[i]);
    return 0;

Although my solution follows the exact same logic it’s failing test case 3. (You can see the test case in the link to my submission after clicking "Click here to see test details at the bottom of the page)

Any idea what I’m doing wrong?



Works like a charm! So in cpp do doubles and floats get rounded? If so then how did it pass test 1 since it that test also has the answer as X.5000… ?

It doesn’t get rounded, but displays it in scientific notation for large values, unless explicitly specified to output in decimal notation.

1 Like

The more you know…
Thanks for suck a quick reply!