fahimkamal63

Four Elements

Apr 19th, 2019
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4.  
  5. int main(){
  6.     int t; cin >> t;
  7.     while(t--){
  8.         int n; cin >> n;
  9.         int a[n], i;
  10.         for(i = 0; i < n; i++){
  11.             cin >> a[i];
  12.         }
  13.         sort(a, a+n);
  14.         int x, flag = 0, j, k, l; cin >> x;
  15.         for(i = 0; i < n-3; i++){
  16.             for(j = i+1; j < n-2; j++){
  17.                 for(k = j+1; k < n-1; k++){
  18.                     for(l = k+1; l < n; l++){
  19.                         if(a[i] + a[j] + a[k] + a[l] == x){
  20.                             flag = 1;
  21.                             break;
  22.                         }
  23.                     }
  24.                     if(flag) break;
  25.                 }
  26.                 if(flag) break;
  27.             }
  28.             if(flag) break;
  29.         }
  30.         if(flag) cout << "1\n";
  31.         else cout << "0\n";
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment