Last active
May 6, 2019 19:30
-
-
Save Rockbet/1b1339c3224cf738f4d02ce974522c0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Noic - Ideia 4 | |
// Exercício 1 | |
// Complexidade: O(N) | |
// Por Leonardo Paes | |
#include <bits/stdc++.h> | |
using namespace std; | |
int v[1000100]; | |
int main(){ | |
int n, x; | |
cin >> n >> x; | |
for(int i=1; i<=n; i++){ | |
cin >> v[i]; | |
} | |
bool resposta=false; | |
for(int l=1, r=n; l<r;){ | |
if(v[l]+v[r]==x){ | |
resposta=true; | |
break; | |
} | |
if(v[l]+v[r]<x){ | |
l++; | |
} | |
if(v[l]+v[r]>x){ | |
r--; | |
} | |
} | |
cout << resposta << endl; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment