CSES - APIO 2016 - Results
Submission details
Task:Gap
Sender:Lieska
Submission time:2019-04-13 12:29:22 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'll findGap(int, int)':
input/code.cpp:23:9: error: 'k' was not declared in this scope
         k=(d-c-1)/(b-1);
         ^

Code

#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
typedef long long ll;
ll findGap(int a, int b){
    ll c=0, d=1e18, e, t[100001], s=0, mn, mx;
    if (a==1){
        for (int i=1; i<=(b+1)/2; ++i){
            MinMax(c, d, &mn, &mx);
            t[i]=mn;
            t[b+1-i]=mx;
            c=mn+1;
            d=mx-1;
        }
        for (int i=1; i<b; ++i){
            c=t[i+1]-t[i];
            if (c>s) s=c;
        }
    }
    else {
        MinMax(0,1e18,&mn,&mx);
        c=mn, d=mx, e=mn;
        k=(d-c-1)/(b-1);
        for (int i=mn+1; i<mx; i+=k+1){
            MinMax(i, i+k, &mn, &mx);
            if (mn!=-1){
                if (mn-e>s) s=mn-e;
                e=mx;
            }
        }
        if (d-e>s) s=d-e;
    }
    return s;
}