Last active
May 3, 2019 18:29
-
-
Save lawrencefmm/1660477e96a35b87314a852135a93265 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
#include <bits/stdc++.h> | |
using namespace std; | |
const int inf = 1e9 + 10; | |
int n, l , r, x; | |
int v[20]; | |
long long resp; | |
int main() | |
{ | |
ios::sync_with_stdio(false), cin.tie(); | |
cin >> n >> l >> r >> x; | |
for(int i = 0; i < n; i++) | |
cin >> v[i]; | |
for(int mask = 0; mask <= (1 << n) - 1; mask++)// percorro todas as bitmasks | |
{ | |
long long s = 0; | |
int maior = 0; | |
int menor = inf; | |
for(int i = 0; i < n; i++)// percorro todos os bits | |
{ | |
if(mask & (1 << i)) //checo se a questão está na prova que estou olhando | |
{ | |
s += v[i]; | |
maior = max(maior, v[i]); // calculo a maior dificuldade | |
menor = min(menor, v[i]); // calculado a menor dificuldade | |
} | |
} | |
if(s >= l and s <= r and (maior - menor) >= x) resp++; // se a prova é valida, adiciono um no contador | |
} | |
cout << resp << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment