ARRT - Editorial

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 :crazy_face:

@ssjgz @cherry0697 @saurabhsingh_1
Can you please check my code & point out where it gets wrong?

https://www.codechef.com/viewsolution/49403396

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.

@ssjgz It must be some other flaw.
Because it gives AC for 2nd test case.

Perhaps the 2nd case is just

1
1
1
1

:stuck_out_tongue: Why take a chance? Just fix it.

@ssjgz
It still doesn’t work :frowning:

https://www.codechef.com/viewsolution/49409023

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
1 Like

@ssjgz,
Thankyou :raised_hands: :blush:
It was a bit silly doubt though :sweat_smile:
This was my first challenge and I am kinda newbie to CP. Hope to do better in further challenges.

1 Like

Input is incomplete @ssjgz

Thanks - edited.

Thank you so much @ssjgz
I have finally figured it out :slight_smile:

1 Like

Can somebody pls help me finding out my mistake .
https://www.codechef.com/viewsolution/49436578

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 ?

Thank you @ssjgz .

1 Like