why m i getting wrong ans for subtask 2 ?
problem : wormholes
#include <iostream>
#include<climits>
#include<algorithm>
using namespace std;
int main() {
int n , x, y ;
cin>>n>>x>>y;
pair<int ,int> a[n];
for(int i=0;i<n;i++)
{
cin>>a[i].first>>a[i].second;
}
int v[x];
for(int i =0;i<x;i++)
{cin>>v[i];}
sort(v,v+x);
int w[y];
for(int i =0;i<y;i++)
{ cin>>w[i];}
sort(w,w+y);
int d,md=INT_MAX;
for(int i=0;i<n;i++)
{ auto l1= lower_bound(v, v+x, a[i].first);
int g = (l1-v);
auto l2= lower_bound(w, w+y, a[i].second);
int h = (l2-w);
d= w[h]-v[g-1]+1;
//cout<<d<<" ";
if(d>=0)
{ md=min(md,d);}
}
cout<<md<<endl;
// your code goes here
return 0;
}
You are not checking the condition
if (contest[i].first >= v[0] && contest[i].second <= w[y-1])
You may see this CodeChef: Practical coding for everyone
thanks a lot that helped!
#include<bits/stdc++.h>
#include
using namespace std;
bool sortbysec(const pair<int,int> &a,
const pair<int,int> &b)
{
return (a.second < b.second);
}
int main() {
long long int a,b,c;
cin>>a>>b>>c;
vector<pair <long long int,long long int>> V(a);
vector X(b);
vector Y©;
long long int q;
for(long long int i=0;i<a;i++)
{
cin>>V[i].first>>V[i].second;
//=q-V[i].first;
}
for(long long int i=0;i<b;i++)
{
cin>>X[i];
}
for(long long int i=0;i<c;i++)
{
cin>>Y[i];
}
// sort(V.begin(), V.end(), sortbysec);
sort(X.begin(),X.end());
sort(Y.begin(),Y.end());
long long int TT,CW,MW=INT_MAX,WA,WB;
for(long long int i=0;i<a;i++)
{ if(V[i].first-V[i].second >= MW)
{
continue;
}
long long int j=0;
WB=V[i].first-X[j];
while(X[j]<=V[i].first && j<b)
{ WB=V[i].first-X[j];
j++;
}
j=0;
while(Y[j]<V[i].second && j<c)
{
j++;
}
WA=Y[j]-V[i].second;
if(WA<0||WB<0)
{
continue;
}
else{
CW=1+(V[i].second-V[i].first)+WA+WB;
}
// cout<<V[i].second<<" "<<WA<<" "<<WB<<" "<<CW<<endl;
if(CW<MW)
{
MW=CW;
}
}
cout<<MW;
// your code goes here
return 0;
}
somebody help me please getting partially correct answer