#include <bits/stdc++.h>
using namespace std;
// ordered set whith s.order_of_key(x) method, which returns rank of element x in set s
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
*/
// pair printing
template <class T, class U>
ostream& operator<<(ostream& out, const pair<T, U> &par) {out << "(" << par.first << "; " << par.second << ")"; return out;}
// set printing
template <class T>
ostream& operator<<(ostream& out, const set<T> &cont) { out << "{"; for(const auto &x:cont) out << x << ", "; out << "}"; return out; }
// map printing
template <class T, class U>
ostream& operator<<(ostream& out, const map<T, U> &cont) {out << "{"; for(const auto &x:cont) out << x << ", "; out << "}"; return out; }
// unordered_set printing
template <class T>
ostream& operator<<(ostream& out, const unordered_set<T> &cont) {out << "{";for(const auto &x:cont) out << x << ", ";out << "}";return out;}
// unordered_map printing
template <class T, class U>
ostream& operator<<(ostream& out, const unordered_map<T, U> &cont) {out << "{";for(const auto &x:cont) out << x << ", ";out << "}";return out;}
// vector printing
template<class T>
ostream& operator<<(ostream& out, const vector<T> &cont){ out << "["; for (const auto &x:cont) out << x << ", "; out << "]"; return out;}
#define print(x) cout << (x) << endl;
#define dmp(x) cerr << #x << " = " << x << endl
#define dmpn(x) cerr << #x << " = " << x << "; "
#define dmpl(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << x << endl
#define int long long
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define pb push_back
#define ff first
#define ss second
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define contains(s,x) ((s).find(x) != (s).end())
const int MOD = 998244353;
void subset_sums(int i, int sum, vector<int> &a, vector<int> &answer) {
if (i == -1) {
answer.pb(sum);
return;
}
subset_sums(i - 1, sum + a[i], a, answer);
subset_sums(i - 1, sum, a, answer);
}
void solve() {
int N, K;
cin >> N >> K;
int M = N / 2;
N = N - M;
vector<int> a(N), b(N);
for (int i = 0; i < N; i++) cin >> a[i];
for (int i = 0; i < M; i++) cin >> b[i];
vector<int> asums, bsums;
subset_sums(N - 1, 0, a, asums);
subset_sums(M - 1, 0, b, bsums);
sort(all(asums));
sort(all(bsums));
int ans = 0;
for (int i = 0, j = sz(bsums) - 1; i < sz(asums); i++) {
while (j >= 0 && asums[i] + bsums[j] > K) j--;
ans += j + 1;
}
cout << ans << endl;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
2532 KB |
Output is correct |
2 |
Correct |
42 ms |
5588 KB |
Output is correct |
3 |
Correct |
171 ms |
21704 KB |
Output is correct |
4 |
Correct |
41 ms |
5588 KB |
Output is correct |
5 |
Correct |
6 ms |
1632 KB |
Output is correct |
6 |
Correct |
5 ms |
1116 KB |
Output is correct |
7 |
Correct |
9 ms |
1756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
3032 KB |
Output is correct |
2 |
Correct |
15 ms |
2520 KB |
Output is correct |
3 |
Correct |
64 ms |
11724 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
1116 KB |
Output is correct |
6 |
Correct |
9 ms |
1752 KB |
Output is correct |
7 |
Correct |
10 ms |
1756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
4564 KB |
Output is correct |
2 |
Correct |
62 ms |
8656 KB |
Output is correct |
3 |
Correct |
69 ms |
8660 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
29 ms |
8444 KB |
Output is correct |
6 |
Correct |
135 ms |
21452 KB |
Output is correct |
7 |
Correct |
60 ms |
8652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
128 ms |
16864 KB |
Output is correct |
2 |
Correct |
15 ms |
2516 KB |
Output is correct |
3 |
Correct |
5 ms |
1116 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
1116 KB |
Output is correct |
6 |
Correct |
122 ms |
16844 KB |
Output is correct |
7 |
Correct |
9 ms |
1632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
2528 KB |
Output is correct |
2 |
Correct |
40 ms |
5532 KB |
Output is correct |
3 |
Correct |
6 ms |
1116 KB |
Output is correct |
4 |
Correct |
6 ms |
1116 KB |
Output is correct |
5 |
Correct |
34 ms |
8448 KB |
Output is correct |
6 |
Correct |
14 ms |
2516 KB |
Output is correct |
7 |
Correct |
162 ms |
21708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
22120 KB |
Output is correct |
2 |
Correct |
16 ms |
2520 KB |
Output is correct |
3 |
Correct |
5 ms |
1112 KB |
Output is correct |
4 |
Correct |
173 ms |
20940 KB |
Output is correct |
5 |
Correct |
43 ms |
10704 KB |
Output is correct |
6 |
Correct |
9 ms |
1756 KB |
Output is correct |
7 |
Correct |
18 ms |
3032 KB |
Output is correct |