Wrong Answer
Code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
long long n;
cin>>n;
vector<long long>a(n);
vector<long long>b(n);
// vector<long long>a1;
// vector<long long>b1;
for(int i=0;i<n;i++)
{
cin>>a[i];
// a1.push_back(a[i]);
}
for(int i=0;i<n;i++)
{
cin>>b[i];
// b1.push_back(b[i]);
}
//prothome a b dekhi
sort(a.begin(),a.end());
sort(b.begin(),b.end());
int check1=0;
int j=0;
int last_even=0;
int last_odd=0;
for(int i=2;i<n;i++) //a er prothom 2 taa ekhon dekhaar dorkaar naai jehetu a check kortaachi
{
//int ind=i+1;
if(i<=3)
{
int j1=0;
if(b[j]<a[i]&&b[j+1]<a[i])
{
j1=j;
j+=2;
// continue;
}
else
{
check1++;
break;
}
if(i%2==0)
{
last_even=b[j1];
}
else
{
last_odd=b[j1];
}
}
else //4 baa taar theke boro
{
if(i%2==0)
{
long long temp1=last_even;
long long temp2=b[j];
if(a[i]>temp1&&a[i]>temp2)
{
last_even=b[j];
j++;
continue;
}
else
{
check1++;
break;
}
}
else if(i%2!=0)
{
long long temp1=last_odd;
long long temp2=b[j];
if(a[i]>temp1&&a[i]>temp2)
{
last_odd=b[j];
j++;
continue;
}
else
{
check1++;
break;
}
}
}
}
// cout<<j<<endl;
//ebar b aar a dekhi
last_even=0;
last_odd=0;
j=0;
int check2=0;
for(int i=2;i<n;i++) //a er prothom 2 taa ekhon dekhaar dorkaar naai jehetu a check kortaachi
{
// int ind=i+1;
if(i<=3)
{
int j1=0;
if(a[j]<b[i]&&a[j+1]<b[i])
{
j1=j;
j+=2;
// continue;
}
else
{
check2++;
break;
}
if(i%2==0)
{
last_even=a[j1];
}
else
{
last_odd=a[j1];
}
}
else //4 baa taar theke boro
{
if(i%2==0)
{
long long temp1=last_even;
long long temp2=a[j];
if(b[i]>temp1&&b[i]>temp2)
{
last_even=a[j];
j++;
continue;
}
else
{
check2++;
break;
}
}
else if(i%2!=0)
{
long long temp1=last_odd;
long long temp2=a[j];
if(b[i]>temp1&&b[i]>temp2)
{
last_odd=a[j];
j++;
continue;
}
else
{
check2++;
break;
}
}
}
}
//cout<<j<<endl;
// cout<<check1<<" "<<check2<<endl;
if(check1!=0&&check2!=0)
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;
}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1193 C. Roy and Peak Array
- Contest
- Brain Booster #10
- Language
- C++11 (G++ 13.2.0)
- Submit At
- 2025-06-13 17:02:51
- Judged At
- 2025-06-13 17:02:51
- Judged By
- Score
- 5
- Total Time
- 66ms
- Peak Memory
- 580.0 KiB