Submission #967716

#TimeUsernameProblemLanguageResultExecution timeMemory
967716jadai007Ice Hockey World Championship (CEOI15_bobek)C++14
90 / 100
299 ms21976 KiB
#include<bits/stdc++.h> #define int long long using namespace std; vector<int> lefts, rights; int arr[1000100], 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))) 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)

bobek.cpp: In function 'int main()':
bobek.cpp:32:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         while(idx < rights.size() && rights[idx] + x <= k) idx++;
      |               ~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...