ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
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.