#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <math.h>
#include <array>
#include <random>
#include <bitset>
#include <climits>
#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl '\n'
#define mod 1000000007
#define INF 0x3f3f3f3f
#pragma GCC optimize("O3,Ofast,unroll-loops")
#pragma GCC target("avx2,sse3,sse4,avx")
#pragma GCC target("popcnt")
template <class x>
using ordered_set = tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<int, int> ipair;
int main()
{
cin.tie(0)->sync_with_stdio(0);
long long a, b;
cin >> a >> b;
vector<int> p1, p2;
for (int i = 0; i < a; i++)
{
if (i < ((a + 1) / 2))
{
int x;
cin >> x;
p1.push_back(x);
}
else
{
int x;
cin >> x;
p2.push_back(x);
}
}
vector<long long> asd;
for (int i = 0; i < (1 << p2.size()); i++)
{
long long sum = 0;
for (int j = 0; j < p2.size(); j++)
{
if (i & (1 << j))
{
sum += p2[j];
}
}
asd.push_back(sum);
}
sort(asd.begin(), asd.end());
long long ans = 0, sum = 0;
for (int i = 0; i < (1 << p1.size()); i++)
{
long long sum = 0;
for (int j = 0; j < p1.size(); j++)
{
if (i & (1 << j))
sum += p1[j];
}
ans += upper_bound(asd.begin(), asd.end(), (b - sum)) - asd.begin();
}
cout << ans;
}
Compilation message
bobek.cpp: In function 'int main()':
bobek.cpp:70:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (int j = 0; j < p2.size(); j++)
| ~~^~~~~~~~~~~
bobek.cpp:87:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for (int j = 0; j < p1.size(); j++)
| ~~^~~~~~~~~~~
bobek.cpp:83:24: warning: unused variable 'sum' [-Wunused-variable]
83 | long long ans = 0, sum = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
440 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
980 KB |
Output is correct |
2 |
Correct |
101 ms |
3532 KB |
Output is correct |
3 |
Correct |
402 ms |
10836 KB |
Output is correct |
4 |
Correct |
94 ms |
3704 KB |
Output is correct |
5 |
Correct |
14 ms |
980 KB |
Output is correct |
6 |
Correct |
7 ms |
724 KB |
Output is correct |
7 |
Correct |
14 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
1488 KB |
Output is correct |
2 |
Correct |
29 ms |
980 KB |
Output is correct |
3 |
Correct |
181 ms |
6704 KB |
Output is correct |
4 |
Correct |
1 ms |
504 KB |
Output is correct |
5 |
Correct |
7 ms |
848 KB |
Output is correct |
6 |
Correct |
16 ms |
992 KB |
Output is correct |
7 |
Correct |
14 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
1660 KB |
Output is correct |
2 |
Correct |
148 ms |
3532 KB |
Output is correct |
3 |
Correct |
147 ms |
3532 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
78 ms |
3500 KB |
Output is correct |
6 |
Correct |
225 ms |
10852 KB |
Output is correct |
7 |
Correct |
80 ms |
3532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
144 ms |
6728 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
192 ms |
10828 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |