This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int NMAX = 50;
int n;
ll v[NMAX];
ll m, res;
vector < ll > a1;
vector < ll > a2;
void solve(int pos, int lim, ll sum, vector < ll > &a) {
if(pos == lim) {
a.push_back(sum);
return;
}
solve(pos + 1, lim, sum, a);
solve(pos + 1, lim, sum + v[pos], a);
}
int main()
{
ios::sync_with_stdio(false);
cin >> n >> m;
for(int i = 0; i < n; i++)
cin >> v[i];
solve(0, n / 2, 0, a1);
sort(a1.begin(), a1.end());
solve(n / 2, n, 0, a2);
sort(a2.begin(), a2.end());
int val = a2.size() - 1;
for(int i = 0; i < a1.size(); ++i) {
if(m < a1[i])
break;
while(a2[val] > m - a1[i] && 0 <= val)
val--;
res += val;
res++;
}
cout << res << '\n';
return 0;
}
Compilation message (stderr)
bobek.cpp: In function 'int main()':
bobek.cpp:44:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < a1.size(); ++i) {
~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |