-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_AquaMoon_and_Two_Arrays.cpp
61 lines (50 loc) · 1021 Bytes
/
A_AquaMoon_and_Two_Arrays.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<bits/stdc++.h>
using namespace std;
#define int long long
int main(){
int t;
cin>>t;
while(t--){
int n,m;
cin>>n;
int xor=1;
int a[n],b[n];
for(int i = 0; i<n;i++){
cin>>a[i];
}
for(int i = 0; i<n;i++){
cin>>b[i];
}
int xnor=1;
vector<pair<int,int>> l,r,ans;
int s1=0,s2=0;
for(int i=0;i<n;i++){
if(a[i]<b[i]) l.push_back({i,b[i]-a[i]});
else if(a[i]>b[i]) r.push_back({i,a[i]-b[i]});
s1+=a[i];
s2+=b[i];
}
if(s1!=s2) {
cout<<-1<<endl;
continue;
}
int x=0;int y=0;
while(x<l.size() and y<r.size())
{
int c=min(l[x].second,r[y].second);
for(int i=0;i<c;i++){
ans.push_back({l[x].first,r[y].first});
}
l[x].second-=c,r[y].second-=c;
if(l[x].second==0) x++;
if(r[y].second==0) y++;
}
if(x==l.size() and y==r.size())
{
cout<<ans.size()<<"\n";
for(auto &[x,y]:ans) cout<<y+1<<" "<<x+1<<endl;
}
else cout<<-1<<endl;
// cout<<endl;
}
}