#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Nmax = 100;
ll ans = 0, sum, money;
vector<ll> A, B;
int a[Nmax], b[Nmax], i, j, n, m;
int main()
{
// freopen("input", "r", stdin);
// freopen("output", "w", stdout);
cin.sync_with_stdio(false);
cin >> n >> money;
m = n>>1; n -= m;
for(i=0; i<n; ++i) cin >> a[i];
for(i=0; i<m; ++i) cin >> b[i];
for(i=0; i<(1<<n); ++i)
{
sum = 0;
for(j=0; j<n; ++j)
if(i & (1<<j)) sum += a[j];
A.push_back(sum);
}
for(i=0; i<(1<<m); ++i)
{
sum = 0;
for(j=0; j<m; ++j)
if(i & (1<<j)) sum += b[j];
B.push_back(sum);
}
sort(A.begin(), A.end());
reverse(A.begin(), A.end());
sort(B.begin(), B.end());
j = 0;
for(i=0; i<A.size(); ++i)
{
while(j<B.size() && A[i] + B[j] <= money) ++j;
ans += j;
}
cout << ans << '\n';
return 0;
}
Compilation message
bobek.cpp: In function 'int main()':
bobek.cpp:44:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0; i<A.size(); ++i)
~^~~~~~~~~
bobek.cpp:46:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(j<B.size() && A[i] + B[j] <= money) ++j;
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
496 KB |
Output is correct |
2 |
Correct |
2 ms |
544 KB |
Output is correct |
3 |
Correct |
2 ms |
544 KB |
Output is correct |
4 |
Correct |
2 ms |
544 KB |
Output is correct |
5 |
Correct |
2 ms |
660 KB |
Output is correct |
6 |
Correct |
2 ms |
704 KB |
Output is correct |
7 |
Correct |
2 ms |
816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
816 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
816 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
2768 KB |
Output is correct |
2 |
Correct |
92 ms |
5880 KB |
Output is correct |
3 |
Correct |
408 ms |
21288 KB |
Output is correct |
4 |
Correct |
90 ms |
21288 KB |
Output is correct |
5 |
Correct |
17 ms |
21288 KB |
Output is correct |
6 |
Correct |
12 ms |
21288 KB |
Output is correct |
7 |
Correct |
25 ms |
21288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
21288 KB |
Output is correct |
2 |
Correct |
34 ms |
21288 KB |
Output is correct |
3 |
Correct |
161 ms |
21288 KB |
Output is correct |
4 |
Correct |
2 ms |
21288 KB |
Output is correct |
5 |
Correct |
9 ms |
21288 KB |
Output is correct |
6 |
Correct |
22 ms |
21288 KB |
Output is correct |
7 |
Correct |
22 ms |
21288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
21288 KB |
Output is correct |
2 |
Correct |
140 ms |
21288 KB |
Output is correct |
3 |
Correct |
139 ms |
21288 KB |
Output is correct |
4 |
Correct |
2 ms |
21288 KB |
Output is correct |
5 |
Correct |
100 ms |
21288 KB |
Output is correct |
6 |
Correct |
335 ms |
21296 KB |
Output is correct |
7 |
Correct |
146 ms |
21296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
174 ms |
21296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
21296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
229 ms |
21484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |