aboutsummaryrefslogtreecommitdiff
path: root/BinarySearch
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2022-11-01 11:51:53 +0200
committeromagdy7 <omar.professional8777@gmail.com>2022-11-01 11:51:53 +0200
commit91ca20b8f78eeeb74fc4eea6eeecdca9fefa5656 (patch)
tree0b8fa3a57f5e442c8134f089e64019aba89c5b19 /BinarySearch
parentf2c878488b659cd19ccecc9880e042251585fdbb (diff)
downloadcompetitive-programming-91ca20b8f78eeeb74fc4eea6eeecdca9fefa5656.tar.xz
competitive-programming-91ca20b8f78eeeb74fc4eea6eeecdca9fefa5656.zip
Added new problems
Diffstat (limited to 'BinarySearch')
-rwxr-xr-xBinarySearch/mainbin0 -> 27472 bytes
-rw-r--r--BinarySearch/main.cpp38
-rw-r--r--BinarySearch/main_input0.txt3
-rw-r--r--BinarySearch/main_output0.txt10
4 files changed, 51 insertions, 0 deletions
diff --git a/BinarySearch/main b/BinarySearch/main
new file mode 100755
index 0000000..fc015d6
--- /dev/null
+++ b/BinarySearch/main
Binary files differ
diff --git a/BinarySearch/main.cpp b/BinarySearch/main.cpp
new file mode 100644
index 0000000..2dbe7fe
--- /dev/null
+++ b/BinarySearch/main.cpp
@@ -0,0 +1,38 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+bool bs(vector<int> &a, int toFind) {
+ int low = 0;
+ int high = a.size() - 1;
+ int mid = (high + low) / 2;
+ while (low <= high) {
+ if (a[mid] == toFind) {
+ return true;
+ } else if (a[mid] > toFind) {
+ high = mid - 1;
+ } else if(a[mid] < toFind){
+ low = mid + 1;
+ }
+ mid = (high + low) / 2;
+ }
+ return false;
+}
+
+int main() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int n, k;
+ cin >> n >> k;
+
+ vector<int> a(n);
+ vector<int> q(n);
+
+ for (int &x : a)
+ cin >> x;
+ for (int i = 0; i < k; i++) {
+ int y;
+ cin >> y;
+ cout << (bs(a, y) ? "YES" : "NO") << endl;
+ }
+}
diff --git a/BinarySearch/main_input0.txt b/BinarySearch/main_input0.txt
new file mode 100644
index 0000000..0b33549
--- /dev/null
+++ b/BinarySearch/main_input0.txt
@@ -0,0 +1,3 @@
+10 10
+1 61 126 217 2876 6127 39162 98126 712687 1000000000
+100 6127 1 61 200 -10000 1 217 10000 1000000000
diff --git a/BinarySearch/main_output0.txt b/BinarySearch/main_output0.txt
new file mode 100644
index 0000000..9b9d3c3
--- /dev/null
+++ b/BinarySearch/main_output0.txt
@@ -0,0 +1,10 @@
+NO
+YES
+YES
+YES
+NO
+NO
+YES
+YES
+NO
+YES