This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//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(auto A : a){
while(p2 >= 0 and A + b[p2] > m)
p2--;
ans += (p2 + 1);
if(p2 < 0)
break;
}
return ans;
}
long long solve(){
int mid = n / 2;
create(0, mid, a);
create(mid, n, b);
return matches();
}
int main(){
input();
cout << solve();
}
# | 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... |