We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 35f4174 commit da230e1Copy full SHA for da230e1
Vectors/(CODECHEF) CSUM - Chef and Sum.cpp
@@ -0,0 +1,36 @@
1
+#include <iostream>
2
+#include<bits/stdc++.h>
3
+#define lli long long int
4
+using namespace std;
5
+
6
+int main() {
7
+ lli t;
8
+ cin>>t;
9
+ while(t--){
10
+ lli n,k,i,j;
11
+ cin>>n>>k;
12
+ int flag = 0;
13
+ lli a[n];
14
+ for(i = 0; i<n; cin>>a[i], i++);
15
+ i = 0;
16
+ j = n-1;
17
+ sort(a,a+n);
18
+ while(i<j){
19
+ if ((a[i]+a[j])==k){
20
+ flag = 1;
21
+ cout<<"Yes"<<"\n";
22
+ break;
23
+ }
24
+ else if((a[i]+a[j])>k){
25
+ j--;
26
27
+ else{
28
+ i++;
29
30
31
+ if (!flag){
32
+ cout<<"No"<<"\n";
33
34
35
+ return 0;
36
+}
0 commit comments