Submission #1085767

#TimeUsernameProblemLanguageResultExecution timeMemory
1085767juicyIce Hockey World Championship (CEOI15_bobek)C++17
100 / 100
303 ms20916 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; long long k; cin >> n >> k; vector<long long> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<long long> lt, rt; for (int m = 0; m < (1 << n / 2); ++m) { long long sum = 0; for (int i = 0; i < n / 2; ++i) { if (m >> i & 1) { sum += a[i]; } } lt.push_back(sum); } for (int m = 0; m < (1 << n - n / 2); ++m) { long long sum = 0; for (int i = 0; i < n - n / 2; ++i) { if (m >> i & 1) { sum += a[n / 2 + i]; } } rt.push_back(sum); } sort(lt.rbegin(), lt.rend()); sort(rt.begin(), rt.end()); int j = 0; long long res = 0; for (auto x : lt) { while (j < rt.size() && rt[j] + x <= k) { ++j; } res += j; } cout << res; return 0; }

Compilation message (stderr)

bobek.cpp: In function 'int main()':
bobek.cpp:29:31: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   29 |   for (int m = 0; m < (1 << n - n / 2); ++m) {
      |                             ~~^~~~~~~
bobek.cpp:43:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     while (j < rt.size() && rt[j] + x <= k) {
      |            ~~^~~~~~~~~~~
#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...