I was trying to solve the practise problem name Max and Electrical panel
the question is :https://www.codechef.com/problems/MAXEP
I wanted to apporach the problem by dividing into smaller parts of 1000 then 100 and then applying linear search. but my code doesn’t seem to work. can someone point out what is the problem wiht the code:
The code that I was trying is :
#include<iostream>
int main()
{
int n, c;
std::cin >> n >> c;
int money = 1000;
int low, high;
low = 1;
high = n;
int ans;
for (int i = 1000; i <= n; i += 1000)
{
std::cout << 1 << " " << i << std::endl;
std::cin >> ans;
if (ans == 0)
{
low = i;
money -= 1;
}
else
{
money -= c;
high = i;
break;
}
}
if ((high - low) > 100)
{
for (int i = low; i <= high; i += 100)
{
std::cout << 1 << " " << i << std::endl;
std::cin >> ans;
if (ans == 0)
{
low = i;
money -= 1;
}
else
{
money -= c;
high = i;
}
}
}
for (int i = low; i <= high; i++)
{
std::cout << 1 << " " << i << std::endl;
std::cin >> ans;
if (ans == 1)
{
std::cout << 3 << " " << i << std::endl;
break;
}
}
std::cin.get();
std::cin.get();
}
The result was: https://www.codechef.com/viewsolution/22044353
I also wanted to know whether the approach is good or it is flawed. If not whats going wrong?
As such there are no syntax or compile errors but on submitting its shows wrong answer.
Also I am new to competetive coding so any tips would be appreciated.