# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
967721 | jadai007 | Ice Hockey World Championship (CEOI15_bobek) | C++14 | 293 ms | 22432 KiB |
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<bits/stdc++.h>
#define int long long
using namespace std;
vector<int> lefts, rights;
int arr[50], n, k, idx, ans;
void solve(int l, int r){
for(int i = 0; i < (1<<(r - l + 1)); ++i){
int sum = 0;
for(int j = l; j <= r; ++j) if(i&(1<<(j - l + 1))) sum += arr[j];
if(l == 1) lefts.push_back(sum);
else rights.push_back(sum);
}
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> k;
for(int i = 1; i <= n; ++i) cin >> arr[i];
if(n == 1){
if(arr[1] <= k) cout << 1;
else cout << 0;
return 0;
}
solve(1, n / 2);
solve(n / 2 + 1, n);
sort(lefts.begin(), lefts.end()); sort(rights.begin(), rights.end());
reverse(lefts.begin(), lefts.end());
for(auto x:lefts){
while(idx < rights.size() && rights[idx] + x <= k) idx++;
ans+=idx;
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | 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... |