ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
back to board

Discussion of Problem 1021. Sacrament of the Sum

Hint, Solution & Code(C++)
Posted by Asif Anwar Sajid 3 Apr 2021 11:52
Hint: Binary search!!

Solution: This is a pretty easy binary search problem. All we need is to check for every number of the second list(as first list is sorted in ascending order) let's denote as x, if we can find y = 10000-x in the first list. If we find y for any x(from the 2nd list) then we will print "YES". Because we already got a pair x, y for which x + y = 10000.

So, the complexity is NlogN(as we are doing binary search for every element of a list in the worst case).

[Code was deleted]

Edited by moderator 06.06.2021 03:06
Re: Hint, Solution & Code(C++)
Posted by Garibaldi 1 Jun 2021 13:46
Binary search is not needed here. It is enough to traverse the array with two pointers.