ARRTWIST - TWISTED ARRAY
There are two integer arrays A and B. The length of array A is n and length of array B is k. Array A = [ a1 , a2 , ... , ai ... , an ] and B = [ b1 , b2 , ... , bj ... , bk ] where 1 <= ai <= k and 1 <= bj <= n and 1 <= i <= n and 1 <= j <= k and 1 <= k <= n <= 107. If there exists a subarray of A which has the same sum as some subarray of B then B and A are said to be twisted arrays.
More mathematically, if there exists p, q, r and s such that sum(A, p, q) = sum(B, r, s), where 1 <= p <= q <= n and 1 <= r <= s <= k and sum(A, p, q) = ap + ap+1 + ap+2 ... + aq-1 + aq and sum(B, r, s) = br + br+1 + br+2 ... + bs-1 + bs then the two arrays A and B are said to be twisted arrays.
Input contains n + k + 1 lines. The first line has values for n and k separated by space.
Then next n lines specify the elements of array A. The next k lines specify the elements of array B.
One line containing Yes if the arrays are twisted or No otherwise (Note: Yes and No are case sensitive)
Here A = [1, 2, 3, 1] and B = [2, 1, 1]. Clearly a1 + a2 = b1 + b2 . And so A and B are twisted
My personal opinion is that problems like this are OK, but this one is pretty blatantly given away by **([amit9oct] Reduced the limits :P)** combined with the oh so subtle **([amit9oct] Removed the not so subtle hint :P)**.
1 <= ai <= k and 1 <= bj <= n this is important
Made a guess based on AC runtimes and passed. (@amit9oct Reply: removed the spoiler). This means eg. arrays A =  and B =  are not twisted, but either no such testcase exists or the statement is wrong. (@amit9oct Reply: Please read the question carefully A =  and B =  doesn't even qualify as a valid input because len(A) = 1 so B cannot have any number greater than 1 hence B cannot contain 2)
Last edit: 2018-08-27 13:27:36
why NZEC for python?