Edit: What if there is no such i where (a[0] + b[i])\ \%\ N is 0?
Example:
n = 3
a[] = {1, 4, 6}
b[] = {1, 3, 6}
Now, a[0] % 3 = 1
and there is no element in b
whose modulo 3 is 2.
What would you do then?
Edit: What if there is no such i where (a[0] + b[i])\ \%\ N is 0?
Example:
n = 3
a[] = {1, 4, 6}
b[] = {1, 3, 6}
Now, a[0] % 3 = 1
and there is no element in b
whose modulo 3 is 2.
What would you do then?
then we take the first two elements
if(end iterator is returned) as b[last index]%n + a[0]%n will be less than n
so adding small values will be only optimal
else we have to take two end values if we cannot take it we take ony last index
e.g n = 5
a[] = { 2,4,6,10} b[]%n = {1,1,2,4,4}
a[] = {2,4,6,10} b[] %n = {0,1,1,2,4}
taking end two values because if we take anyone less than that it(c[0]) will have at least value a[i]%n and even if end values are n-1 still it would be less than a[i]%n
as (n-1 + a[i]%n)%n will give a[i]%n - 1
thanks bro it got accepted i was doing implementation incorrectly.
https://www.codechef.com/viewsolution/49393417
Learned a great thing that abt the lexicographically smaller listâŚjust put in the vector u good to go
On my machine, your solution gives:
1
2
0
for the sample test input, which is not in the format the Output Format asks for.
Perhaps the 2nd case is just
1
1
1
1
Why take a chance? Just fix it.
Consider the test input:
1
5
1 10 8 9 3
10 9 4 5 2
Can anyone please explain whatâs wrong with this code?-PYTH 3.6
https://www.codechef.com/viewsolution/49411783
Consider the test input:
1
2
2 1
2 4
@ssjgz,
Thankyou
It was a bit silly doubt though
This was my first challenge and I am kinda newbie to CP. Hope to do better in further challenges.
Thanks - edited.
One doubt : since there can be at max 2 such starting points, lets say we stored them in st[], so why canât we just compare the next element in the sequence formed by these 2 starting points i.e.
next_1=( a[(0+1)%n] + b[(st[0]+1)%n] )%n,
next_2= ( a[(0+1)%n] + b[(st[1]+1)%n] )%n
since first element of lexicographic sequence that is the correct answer is same, we just need to compare the next element of the both candidate solutions and go with building the smaller one i.i if(next_1<next_2) sp[0] is generator else sp[1] is generator of the solution sequence. I even submitted such code which passed 2nd subtask and failed 1st subtask. Can someone explain on what kind of testcase it would fail ?