# Untitled

unknown
plain_text
14 days ago
1.3 kB
2
Indexable
Never
```#include <bits/stdc++.h>
#define endl '\n'
#define maxn 100005
#define For(i,a,b) for ( int i = a; i <= b; i++ )
#define Ford(i,a,b) for ( int i = a; i >= b; i-- )
#define MOD 100000000000007

using namespace std;
int n,m,a[maxn],b[maxn],u[maxn],v[maxn],top;
void inp()
{
cin >> n;
For(i,1,n) cin >> a[i];
cin >> m;
For(i,1,m) cin >> b[i];
}
bool check(int k)
{
int j = 1;
For(i,1,n)
if(a[i] < k)
{
while(a[i] + b[j] < k)
{
j++;
if(j > m) return false;
}
j++;
}
return true;
}
void print(int k)
{
top = 0;
int j = 1;
For(i,1,n)
if(a[i] < k)
{
while(a[i] + b[j] < k) j++;
u[++top] = i; v[top] = j;
j++;
}
cout << top << endl;
For(i,1,top)
cout << u[i] << " " << v[i] << endl;
}
int main()
{
ios_base:: sync_with_stdio(0);
cin.tie(0);
if(fopen("bai1.inp","r")){
freopen("bai1.inp","r",stdin);
}
inp();
int l,r;
l = 1;
r = 1e9;
while(r - l > 1)
{
int mid = (r+l)/2;
if(check(mid)) l = mid;
else r = mid;
}
cout << l << " ";
print(l);
return 0;
}
```