forked from projectX-india/madlab-hack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathARRT.cpp
94 lines (93 loc) · 2.01 KB
/
ARRT.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include<bits/stdc++.h>
using namespace std;
vector<long long int> call(vector<long long int>&A, vector<long long int>&B, int ind){
vector<long long int> C;
for(long long int i=ind;i<B.size();i++){
C.push_back(B[i]);
}
for(long long int i=0;i<ind;i++){
C.push_back(B[i]);
}
vector<long long int> ans;
for(long long int i=0;i<A.size();i++){
ans.push_back((A[i]+C[i])%(A.size()));
}
return ans;
}
int main(){
long long int t;
cin>>t;
vector<vector<long long int> > ans;
for(long long int i=0;i<t;i++){
long long int n;
cin>>n;
vector<long long int> A;
vector<long long int> B;
for(long long int j=0;j<n;j++){
long long int a;
cin>>a;
A.push_back(a);
}
long long int v = A[0];
vector<long long int> index;
index.push_back(-1);
long long int s = INT_MAX;
for(long long int j=0;j<n;j++){
long long int b;
cin>>b;
B.push_back(b);
if((v+b)%n<s){
s = (v+b)%n;
index.clear();
index.push_back(j);
}
else if((v+b)%n==s){
index.push_back(j);
}
}
for(long long int j=1;j<n;j++){
long long int x = A[j];
if(index.size()>1){
vector<long long int> neww;
long long int s = INT_MAX;
for(long long int k=0;k<index.size();k++){
if(index[k]+j<n){
if((x+B[index[k]+j])%n<s){
s = (x+B[index[k]+j])%n;
neww.clear();
neww.push_back(index[k]);
}
else if((x+B[index[k]+j])%n==s){
neww.push_back(index[k]);
}
}
else if(index[k]+j>=n){
long long int c = index[k]+j-n;
if((x+B[c])%n<s){
s = (x+B[c])%n;
neww.clear();
neww.push_back(index[k]);
}
else if((x+B[c])%n==s){
neww.push_back(index[k]);
}
}
}
index.clear();
for(long long int k=0;k<neww.size();k++){
index.push_back(neww[k]);
}
neww.clear();
}
}
vector<long long int> final = call(A,B,index[0]);
ans.push_back(final);
}
for(long long int i=0;i<t;i++){
for(long long int j=0;j<ans[i].size();j++){
cout<<ans[i][j]<<" ";
}
cout<<endl;
}
return 0;
}