Last active
May 7, 2019 01:29
-
-
Save Rockbet/f78484afa40c956c4414cdf9f0eb8acd 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 2 | |
// Complexidade: O(N) | |
// Por Leonardo Paes | |
#include <bits/stdc++.h> | |
using namespace std; | |
int v[3000000]; | |
int main(){ | |
int n, x, resposta = 0, soma; | |
cin >> n >> x; | |
for(int i = 1; i <= n; i++){ | |
cin >> v[i]; | |
v[n+i]=v[i]; | |
} | |
soma=v[1]; | |
for(int l=1, r=1; l<=n;){ | |
if(r-l>n){ | |
soma-=v[l]; | |
l++; | |
} | |
else if(soma<x){ | |
r++; | |
soma+=v[r]; | |
} | |
else if(soma>x){ | |
soma-=v[l]; | |
l++; | |
} | |
else if(soma == x){ | |
resposta++; | |
r++; | |
soma+=v[r]; | |
soma-=v[l]; | |
l++; | |
} | |
} | |
cout << resposta << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment