Skip to content

Instantly share code, notes, and snippets.

@yaki29
Created June 24, 2018 18:43
Show Gist options
  • Save yaki29/0d0dda3438c716c9b949547d50b1f1e5 to your computer and use it in GitHub Desktop.
Save yaki29/0d0dda3438c716c9b949547d50b1f1e5 to your computer and use it in GitHub Desktop.
using namespace std;
#include <bits/stdc++.h>
#define trace(x) cout<<#x<<": "<<x<<" ";
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
int a[n+1], d[k+1];
for(int i = 0; i<n; i++)
cin>>a[i];
for(int i =0; i<k; i++)
cin>>d[i];
map<int, int> umap;
umap[d[0]] = 0;
for(int i = 1; i<k; i++)
{
d[i] = max(d[i], d[i-1]);
umap[d[i]] = i;
}
int mx = -1, pr = 0;
for(int i = 0; i<n; i++)
{
for(auto it = umap.begin(); it!= umap.end(); it++)
{
int x = (*it).first;
int ind = (*it).second;
if(a[i]>=x)
{
if(mx < ind)
{
pr = i;
mx = ind;
}
}
else
break;
}
}
cout<<pr<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment