The solution to this question of Hostel visit is coming wrong for test case 1

#include
#include
#include
using namespace std;

int main() {
int n,k,q,i=1;
set s;
cin>>n>>k;
while(n–){
cin>>q;
if(q==1){
int x,y;
long long d;
cin>>x>>y;
d=abs(xx+yy);
s.insert(d);
}
if(q==2){
int temp=k,r=0;
for(auto it=s.begin();it!=s.end()&&temp>0;it++,temp–)
r=*it;
cout<<r<<endl;
}
}
return 0;
}

hey @saikatchoudhury1998 please make x, y long long as well and ensure that is of long long type as well.

also use multiset, instead of set as multiple points can have same distance.

#include #include #include using namespace std; int main() { int n,k,q,i=1; multiset s; cin>>n>>k; while(n–){ cin>>q; if(q==1){ long long x,y,d; cin>>x>>y; d=abs(xx+yy); s.insert(d); } if(q==2){ int temp=k,r=0; for(auto it=s.begin();it!=s.end()&&temp>0;it++,temp–) r=*it; cout<<r<<endl; } } return 0; }

I have modified both the modifications still it’s not happening

hey @saikatchoudhury1998 please share code through ide.codingblocks.com, code is changed when it is shared through comments like these.

https://ide.codingblocks.com/s/200972 —> multiset + long long

@saikatchoudhury1998 your set is long long and you are storing value of set in r but is int, how will it work?
Please make x,y,r long long as well.
Please refer to this code: https://ide.codingblocks.com/s/201145

Thanks alot sir, It worked for me

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.