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
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.
Output
One line containing Yes if the arrays are twisted or No otherwise (Note: Yes and No are case sensitive.)
Example
Input:4 3
1
2
3
1
2
1
1 Output: Yes
Explanation:
Here A = [1, 2, 3, 1] and B = [2, 1, 1]. Clearly a1 + a2 = b1 + b2, and so A and B are twisted
hide comments
tojra:
2021-07-02 10:50:02
where can i get help for solution to this problem?
|
|
Amitayush Thakur:
2020-01-30 19:15:48
Anyone posting answers here, I will make sure their submissions and all submissions after their comment are disqualified. Their comments will be edited or removed completely. So don't post answer or any hints here. You solved the problem keep it to yourself (it is no rocket science) and let others solve it too. Solving a problem is not a big deal, knowing/ learning something new is important. If you feel you learnt something new solving this problem then enjoy or else move on don't spoil it for curious and enthusiasts who enjoy learning. I check solutions and comments regularly. So take this comment seriously. I have already disqualified many solvers who posted answers here. Don't do the same mistake. Last edit: 2020-01-30 19:48:24 |
|
hodobox:
2018-12-27 21:40:36
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)**.
|
|
urimaj:
2018-11-17 09:51:44
1 <= ai <= k and 1 <= bj <= n this is important |
|
nadstratosfer:
2018-10-01 15:36:19
Made a guess based on AC runtimes and passed. (@amit9oct Reply: removed the spoiler). This means eg. arrays A = [1] and B = [2] are not twisted, but either no such testcase exists or the statement is wrong. (@amit9oct Reply: Please read the question carefully A = [1] and B = [2] 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)
|
|
aniket_11kg:
2018-07-14 15:14:23
why NZEC for python?
|
Added by: | Amitayush Thakur |
Date: | 2018-07-13 |
Time limit: | 0.5s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | Own |