forked from ek001/cpp-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadc.cpp
53 lines (48 loc) · 1.04 KB
/
adc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
///////// ///// //// ////
// // // // // // //
////// // // // // //
// // /// // // //
//////// // // // //
*/
#include<bits/stdc++.h>
#include<assert.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fo(i,s,n) for(int i=s;i<n;i++)
#define mod 1000000007
int main()
{
Fast
ll n,q;
cin>>n>>q;
ll a[n];
fo(i,0,n)
{
cin>>a[i];
}
while(q--)
{
int b,e;
cin>>b>>e;
set<ll>s;
for(int mask=0;mask<(1<<n);mask++)
{
ll sum=0;
for(int i=0;i<n;i++)
{
if(mask&(1<<i))
{
sum+=a[i];
}
}
if(sum>=b&&sum<=e)
s.insert(sum);
}
cout<<s.size()<<endl;
s.clear();
}
return 0;
}