can anyone tell me whats wrong with my solution for this question
Chef Goes to the Cinema Practice Coding Problem (codechef.com)
this is my solution i used a simple bs on array
#include<bits/stdc++.h>
using namespace std;
define ll long long
ll findFloor(vector arr, int n, ll x) {
ll low = 0, high = n - 1;
ll ans = -1;
while (low <= high) {
int mid = (low + high) / 2;
// maybe an answer
if (arr[mid] <= x) {
ans = mid;
//look for smaller index on the left
low = mid + 1;
}
else {
high = mid - 1; // look on the right
}
}
return ans;
}
ll findCeil(vectorarr, int n, ll x) {
ll low = 0, high = n - 1;
ll ans = -1;
while (low <= high) {
int mid = (low + high) / 2;
// maybe an answer
if (arr[mid] >= x) {
ans = mid;
//look for smaller index on the left
high = mid - 1;
}
else {
low = mid + 1; // look on the right
}
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
vectorseries;
ll i=1;
ll d=2;
while(i<=1e9){
series.push_back(i);
i+=d;
d++;
}
// cout<<series.size()<<“\n”;
// for(int i=0;i<series.size();i++){
// cout<<series[i]<<" “;
// }
while(t–){
ll x;
cin>>x;
ll flo=findFloor(series,series.size(),x);
ll cei=findCeil(series,series.size(),x);
// cout<<flo<<” “<<cei<<”\n";
if(flo==-1){
flo=series.size()-1;
}
if(cei==-1){
cei=series.size()-1;
}
cout<<“flo:-”<<flo<<“value:”<<series[flo]<<" "<<“cei “<<cei<<“value:: “<<series[cei]<<”\n”;
ll for_flo= abs(series[flo]-x)+1+flo;
ll for_cei= abs(series[cei]-x)+1+cei;
cout<<min(for_flo,for_cei)<<”\n”;
}
return 0;
}