#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const double PI = 4 * atan(1);
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>
#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
void fast_io(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void io(string taskname){
string fin = taskname + ".in";
string fout = taskname + ".out";
const char* FIN = fin.c_str();
const char* FOUT = fout.c_str();
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
fast_io();
}
vector<ll> a;
int main(){
fast_io();
int n;
ll m;
vector<ll> f;
vector<ll> s;
cin >> n >> m;
int x = n/2;
int y = n-x;
f0r(i, n){
ll ai;
cin >> ai;
if(i<x){
f.eb(ai);
}
else s.eb(ai);
}
vector<ll> a;
vector<ll> b;
f0r(i, (1<<x)){
ll tmp = 0;
f0r(j, x){
if(((1<<j)& i)>0){
tmp += f[j];
}
}
a.eb(tmp);
}
f0r(i, (1<<y)){
ll tmp = 0;
f0r(j, y){
if(((1<<j)& i)>0){
tmp += s[j];
}
}
b.eb(tmp);
}
sort(all(a));
sort(all(b));
//cout << a << endl;
//cout << b << endl;
ll ptr = 0;
ll ans = 0;
for(int i = sz(a)-1; i>= 0; i--){
while(ptr +1<sz(b) && b[ptr+1] + a[i]<=m){
ptr++;
}
//cout << i << " " << ptr << endl;
if(b[ptr] + a[i] <= m)
ans += (ptr + 1);
}
cout << ans << endl;
return 0;
}
Compilation message
bobek.cpp:1:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/stack:200000000")
bobek.cpp: In function 'void io(std::__cxx11::string)':
bobek.cpp:50:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FIN, "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~
bobek.cpp:51:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FOUT, "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
252 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
416 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
2076 KB |
Output is correct |
2 |
Correct |
96 ms |
5452 KB |
Output is correct |
3 |
Correct |
417 ms |
20948 KB |
Output is correct |
4 |
Correct |
96 ms |
5480 KB |
Output is correct |
5 |
Correct |
19 ms |
1652 KB |
Output is correct |
6 |
Correct |
13 ms |
1016 KB |
Output is correct |
7 |
Correct |
25 ms |
1652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
2924 KB |
Output is correct |
2 |
Correct |
35 ms |
2080 KB |
Output is correct |
3 |
Correct |
171 ms |
10592 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
10 ms |
1020 KB |
Output is correct |
6 |
Correct |
23 ms |
1648 KB |
Output is correct |
7 |
Correct |
23 ms |
1652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
3564 KB |
Output is correct |
2 |
Correct |
146 ms |
6672 KB |
Output is correct |
3 |
Correct |
148 ms |
6752 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
102 ms |
6736 KB |
Output is correct |
6 |
Correct |
357 ms |
20952 KB |
Output is correct |
7 |
Correct |
143 ms |
6756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
303 ms |
12888 KB |
Output is correct |
2 |
Correct |
36 ms |
2036 KB |
Output is correct |
3 |
Correct |
12 ms |
1016 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
10 ms |
1016 KB |
Output is correct |
6 |
Correct |
296 ms |
12820 KB |
Output is correct |
7 |
Correct |
23 ms |
1652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
2036 KB |
Output is correct |
2 |
Correct |
95 ms |
5480 KB |
Output is correct |
3 |
Correct |
13 ms |
1016 KB |
Output is correct |
4 |
Correct |
13 ms |
1016 KB |
Output is correct |
5 |
Correct |
108 ms |
6600 KB |
Output is correct |
6 |
Correct |
34 ms |
2036 KB |
Output is correct |
7 |
Correct |
395 ms |
20920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
401 ms |
20824 KB |
Output is correct |
2 |
Correct |
35 ms |
2032 KB |
Output is correct |
3 |
Correct |
13 ms |
1012 KB |
Output is correct |
4 |
Correct |
412 ms |
20904 KB |
Output is correct |
5 |
Correct |
142 ms |
10592 KB |
Output is correct |
6 |
Correct |
23 ms |
1572 KB |
Output is correct |
7 |
Correct |
46 ms |
2928 KB |
Output is correct |