For a problem
when i submitted solution having declaration inside int main() it shows TLE, but when declaration is above int main(), it's accepted in c++.
So my question is does global declaration affects the compilation speed significantly or i am missing something?
Here is the accepted one :
#include<bits/stdc++.h>
using namespace std;
int n,k,m,a=1,c=1;
int main()
{
cin>>n>>m>>k;
m -= n;
while (m>0){
if (k+a<=n) c++;
if (k-a>=1) c++;
m -=c;
a++;
}
cout<<a;
return 0;
}
here is TLE one :
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k,m,a=1,c=1;
cin>>n>>m>>k;
m -= n;
while (m>0){
if (k+a<=n) c++;
if (k-a>=1) c++;
m -=c;
a++;
}
cout<<a;
return 0;
}