Skip to content

Instantly share code, notes, and snippets.

@Rockbet
Last active May 6, 2019 19:30
Show Gist options
  • Save Rockbet/1b1339c3224cf738f4d02ce974522c0d to your computer and use it in GitHub Desktop.
Save Rockbet/1b1339c3224cf738f4d02ce974522c0d to your computer and use it in GitHub Desktop.
// 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