Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h> /* srand, rand */
- #include <time.h> /* time */
- #include <vector>
- #include <algorithm> // std::sort
- using namespace std;
- int main()
- {
- int n,m,x,low,high,mid;
- cin>>n;
- int *arr=new int[n];
- for (int i=0;i<n;i++)
- {
- cin>>arr[i];
- }
- cin>>m;
- int *arr2=new int[m];
- for (int i=0;i<m;i++)
- {
- cin>>arr2[i];
- }
- for(int i=0;i<m;i++)
- {
- x=arr2[i];
- low=0;
- high=n;
- while(high-low>1)
- {
- mid=low+(high-low)/2;
- if (x+arr[mid]>10000)
- high=mid;
- else if(x+arr[mid]<10000)
- low=mid;
- else {
- cout<<"YES";
- return 0;
- }
- }
- if (arr[low]+x==10000)
- {
- cout<<"YES";
- return 0;
- }
- if (arr[high]+x==10000)
- {
- cout<<"YES";
- return 0;
- }
- }
- cout<<"NO";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement