//You can't fill the hole inside you with money, drugs and cars
#include<bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> v, a, b;
void create(int st, int en, vector<long long> &w){
int sz = en - st;
w.push_back(0);
for(int mask = 1; mask < (1 << sz); mask++)
w.push_back(w[mask - (mask & -mask)] + v[st + __builtin_ctz(mask)]);
}
long long inp(){
long long A;
cin >> A;
return A;
}
void input(){
cin >> n >> m;
for(int i = 0; i < n; i++)
v.push_back(inp());
}
long long matches(int p1 = 0, int p2 = b.size() - 1, long long ans = 0){
sort(a.begin(), a.end());
sort(b.begin(), b.end());
for(; p2 >= 0 and p1 < a.size(); p1++){
while(p2 >= 0 and a[p1] + b[p2] > m)
p2--;
ans += (p2 + 1);
}
return ans;
}
long long solve(){
int mid = n / 2;
create(0, mid, a);
create(mid, n, b);
return matches();
}
int main(){
input();
cout << solve();
}
Compilation message
bobek.cpp: In function 'long long int matches(int, int, long long int)':
bobek.cpp:32:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; p2 >= 0 and p1 < a.size(); p1++){
~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
380 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
2032 KB |
Output is correct |
2 |
Correct |
57 ms |
5480 KB |
Output is correct |
3 |
Correct |
235 ms |
20816 KB |
Output is correct |
4 |
Correct |
58 ms |
5476 KB |
Output is correct |
5 |
Correct |
13 ms |
1648 KB |
Output is correct |
6 |
Correct |
10 ms |
1012 KB |
Output is correct |
7 |
Correct |
19 ms |
1644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
2924 KB |
Output is correct |
2 |
Correct |
23 ms |
2028 KB |
Output is correct |
3 |
Correct |
89 ms |
10592 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
8 ms |
1012 KB |
Output is correct |
6 |
Correct |
18 ms |
1644 KB |
Output is correct |
7 |
Correct |
16 ms |
1648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
3560 KB |
Output is correct |
2 |
Correct |
84 ms |
6624 KB |
Output is correct |
3 |
Correct |
85 ms |
6624 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
41 ms |
6752 KB |
Output is correct |
6 |
Correct |
187 ms |
20816 KB |
Output is correct |
7 |
Correct |
91 ms |
6752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
173 ms |
12760 KB |
Output is correct |
2 |
Correct |
26 ms |
2032 KB |
Output is correct |
3 |
Correct |
10 ms |
1012 KB |
Output is correct |
4 |
Correct |
5 ms |
380 KB |
Output is correct |
5 |
Correct |
8 ms |
1012 KB |
Output is correct |
6 |
Correct |
173 ms |
12756 KB |
Output is correct |
7 |
Correct |
16 ms |
1644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
2028 KB |
Output is correct |
2 |
Correct |
57 ms |
5448 KB |
Output is correct |
3 |
Correct |
10 ms |
1012 KB |
Output is correct |
4 |
Correct |
10 ms |
1012 KB |
Output is correct |
5 |
Correct |
50 ms |
6624 KB |
Output is correct |
6 |
Correct |
23 ms |
2036 KB |
Output is correct |
7 |
Correct |
222 ms |
20816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
228 ms |
20820 KB |
Output is correct |
2 |
Correct |
24 ms |
2032 KB |
Output is correct |
3 |
Correct |
10 ms |
1012 KB |
Output is correct |
4 |
Correct |
240 ms |
20820 KB |
Output is correct |
5 |
Correct |
58 ms |
10588 KB |
Output is correct |
6 |
Correct |
16 ms |
1648 KB |
Output is correct |
7 |
Correct |
29 ms |
2924 KB |
Output is correct |