Skip to content

Commit

Permalink
Merge pull request AASF-IIITM#38 from source-aasf/master
Browse files Browse the repository at this point in the history
merge from source-aasf
  • Loading branch information
haritha1313 authored Oct 8, 2018
2 parents a769be9 + 2e63904 commit 4e05c41
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions c++/pihu1-lovestory1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <iostream>
#include <algorithm>
using namespace std;

long long int binarySearch(long long int arr[], long long int startIndex, long long int endIndex, long long int element) {
if (startIndex > endIndex) {
return 0;
}

long long int mid = startIndex + ((endIndex - startIndex) / 2);

if (arr[mid] == element) {
return 1;
}
if (element > arr[mid]) {
return binarySearch(arr, mid + 1, endIndex, element);
} else {
return binarySearch(arr, startIndex, mid - 1, element);
}
}

int main() {
long long int iterator;
cin>>iterator;

while (iterator!=0) {
long long int size;
cin>>size;

long long int arr[size];
for(long long int i=0; i < size; i++) {
cin>>arr[i];
}
int check=0;
long long int totalSum;
cin >> totalSum;

for(long long int i = 0;i<size-2;i++) {
long long int smallSum=totalSum-arr[i];
for(long long int j = i + 1; j < size - 1 ; j++) {
if(binarySearch(arr, j + 1, size - 1, smallSum - arr[j])) {
check++;
break;
}
}
if(check == 1) {
break;
}
}

if(check == 1) {
cout<<"YES"<<endl;
} else {
cout<<"NO"<<endl;
}
iterator--;
}

return 0;
}

0 comments on commit 4e05c41

Please sign in to comment.