-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path24.cpp
More file actions
36 lines (35 loc) · 712 Bytes
/
24.cpp
File metadata and controls
36 lines (35 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(){
//program to find triplet that sums to given value.
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
int x;
cin>>x;
int f = 0;
sort(arr, arr+n);
for(int i=0;i<n-2;i++){
int j = i+1;
int k=n-1;
while(j<k){
int s = arr[i] + arr[j] + arr[k];
if(s==x) {
f = 1;
cout<<true<<endl;
break;
}else if(s>x){
k--;
}else{
j++;
}
}
if(f==1) break;
}
if(f==0)cout<<false<<endl;
return 0;
}