Language: C++

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

typedef int64_t int64;
typedef std::bitset<31> bitset;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n,k;
  cin>>n>>k;
  std::vector<int64> a(n);
  for(int i = 0; i < n; ++i){
    cin>>a[i];
  }

  std::unordered_multiset<bitset> set;

  for(int l=0;l<n;l++){
    int sum=0;
    for(int r=l;r<n;r++){
      sum+=a[r];
      set.insert(bitset(sum));
    }
  }

  for(int bi=30;bi>=0;bi--){
    int count=0;
    for(auto bs:set){
      if(bs[bi]) count++;
    }
    if(count>=k){
      std::unordered_multiset<bitset> new_set;
      for(auto itr=set.begin();itr!=set.end();itr++){
        if((*itr)[bi]){
          new_set.insert(*itr);
        }
      }
      set=new_set;
    }
  }

  if(set.size()==0){
    cout<<0<<endl;
  }else{
    uint32_t result=UINT32_MAX;
    for(auto bs:set){
      result=result&bs.to_ulong();
    }
    cout<<result<<endl;
  }





  return 0;
}


Compiler output:
a.cc:22:14: error: 'bitset' in namespace 'std' does not name a template type
   22 | typedef std::bitset<31> bitset;
      |              ^~~~~~
a.cc:15:1: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
   14 | #include <utility>
  +++ |+#include <bitset>
   15 | #include <vector>
a.cc: In function 'int main()':
a.cc:36:27: error: 'bitset' was not declared in this scope
   36 |   std::unordered_multiset<bitset> set;
      |                           ^~~~~~
a.cc:36:33: error: template argument 1 is invalid
   36 |   std::unordered_multiset<bitset> set;
      |                                 ^
a.cc:36:33: error: template argument 2 is invalid
a.cc:36:33: error: template argument 3 is invalid
a.cc:36:33: error: template argument 4 is invalid
a.cc:42:11: error: request for member 'insert' in 'set', which is of non-class type 'int'
   42 |       set.insert(bitset(sum));
      |           ^~~~~~
a.cc:48:17: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   48 |     for(auto bs:set){
      |                 ^~~
      |                 std::begin
In file included from /usr/include/c++/14/deque:68,
                 from a.cc:5:
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:48:17: error: 'end' was not declared in this scope; did you mean 'std::end'?
   48 |     for(auto bs:set){
      |                 ^~~
      |                 std::end
/usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
a.cc:52:37: error: template argument 2 is invalid
   52 |       std::unordered_multiset<bitset> new_set;
      |                                     ^
a.cc:52:37: error: template argument 3 is invalid
a.cc:52:37: error: template argument 4 is invalid
a.cc:53:24: error: request for member 'begin' in 'set', which is of non-class type 'int'
   53 |       for(auto itr=set.begin();itr!=set.end();itr++){
      |                        ^~~~~
a.cc:53:41: error: request for member 'end' in 'set', which is of non-class type 'int'
   53 |       for(auto itr=set.begin();itr!=set.end();itr++){
      |                                         ^~~
a.cc:55:19: error: request for member 'insert' in 'new_set', which is of non-class type 'int'
   55 |           new_set.insert(*itr);
      |                   ^~~~~~
a.cc:62:10: error: request for member 'size' in 'set', which is of non-class type 'int'
   62 |   if(set.size()==0){
      |          ^~~~
a.cc:65:5: error: 'uint32_t' was not declared in this scope
   65 |     uint32_t result=UINT32_MAX;
      |     ^~~~~~~~
a.cc:15:1: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
   14 | #include <utility>
  +++ |+#include <cstdint>
   15 | #include <vector>
a.cc:66:17: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   66 |     for(auto bs:set){
      |                 ^~~
      |                 std::begin
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:66:17: error: 'end' was not declared in this scope; did you mean 'std::end'?
   66 |     for(auto bs:set){
      |                 ^~~
      |                 std::end
/usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
a.cc:67:7: error: 'result' was not declared in this scope
   67 |       result=result&bs.to_ulong();
      |       ^~~~~~
a.cc:69:11: error: 'result' was not declared in this scope
   69 |     cout<<result<<endl;
      |           ^~~~~~