Problem:


Score : 400 points

Problem Statement

One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N.
He is interested in properties of the sequence a.

For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its beauty is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.)

Find the maximum possible value for him.

Constraints

2 \leq N \leq 1000

1 \leq a_i \leq 10^9

1 \leq K \leq N(N+1)/2

All numbers given in input are integers

Input

Input is given from Standard Input in the following format:

N K
a_1 a_2 ... a_N

Output

Print the answer.

Sample Input 1

4 2
2 5 2 5

Sample Output 1

12

There are 10 nonempty contiguous subsequences of a. Let us enumerate them:

contiguous subsequences starting from the first element: \{2\}, \{2, 5\}, \{2, 5, 2\}, \{2, 5, 2, 5\}

contiguous subsequences starting from the second element: \{5\}, \{5, 2\}, \{5, 2, 5\}

contiguous subsequences starting from the third element: \{2\}, \{2, 5\}

contiguous subsequences starting from the fourth element: \{5\}

(Note that even if the elements of subsequences are equal, subsequences that have different starting indices are considered to be different.)

The maximum possible bitwise AND of the beauties of two different contiguous subsequences is 12.
This can be achieved by choosing \{5, 2, 5\} (with beauty 12) and \{2, 5, 2, 5\} (with beauty 14).

Sample Input 2

8 4
9 1 8 2 7 5 6 4

Sample Output 2

32



Sample input:
4 2
2 5 2 5


Sample output:
12

Submission status: Wrong Answer

Solution code:
import heapq
import numpy
N, K = map(int, input().split())
a = [int(i) for i in input().split()]
res = [0] + list(numpy.cumsum(a))


hq = []
heapq.heapify(hq)  # リストhqのheap化

for i in range(N):
    for j in range(i+1, N+1):
        heapq.heappush(hq, -(res[j]-res[i]))  # heap化されたリストhqに要素xを追加

m = 45
candidate = []
for i in range(N*(N+1)//2):
    a0 = -heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    digit = len(bin(a0))-2
    if digit == m:
        candidate.append(a0)
    else:
        m = digit
        candidate = [a0]
    if len(candidate) >= K:
        break


def countMask(a):
    ret = 0
    for x in candidate:
        if (x & a) == a:
            ret += 1
    return ret


ans = 0

for i in range(40, -1, -1):
    if (countMask(ans | (1 << i)) >= K):
        ans |= 1 << i

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
import numpy
N, K = map(int, input().split())
a = [int(i) for i in input().split()]
res = [0] + list(numpy.cumsum(a))


hq = []
heapq.heapify(hq)  # リストhqのheap化

for i in range(N):
    for j in range(i+1, N+1):
        heapq.heappush(hq, -(res[j]-res[i]))  # heap化されたリストhqに要素xを追加

m = 45
candidate = []
for i in range(N*(N+1)//2):
    a0 = -heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    digit = len(bin(a0))-2
    if digit == m:
        candidate.append(a0)
    else:
        m = digit
        candidate = [a0]
    if len(candidate) >= K:
        break
else:
    print(0)
    exit()

for i in range(m):
    candidate0 = []
    for c in candidate:
        if c & (1 << m-i-1):
            candidate0.append(c)
    if len(candidate0) > K:
        candidate = candidate0
    elif len(candidate0) == K:
        break


ans = candidate0[0]
for c in candidate0[1:K]:
    ans = ans & c
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
import numpy
N, K = map(int, input().split())
a = [int(i) for i in input().split()]
res = [0] + list(numpy.cumsum(a))


hq = []
heapq.heapify(hq)  # リストhqのheap化

for i in range(N):
    for j in range(i+1, N+1):
        heapq.heappush(hq, -(res[j]-res[i]))  # heap化されたリストhqに要素xを追加

m = 45
candidate = []
for i in range(N*(N+1)//2):
    a0 = -heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    digit = len(bin(a0))-2
    if digit == m:
        candidate.append(a0)
    else:
        m = digit
        candidate = [a0]
    if len(candidate) >= K:
        break
else:
    print(0)
    exit()

for i in range(m):
    candidate0 = []
    for c in candidate:
        if c & (1 << m-i-1):
            candidate0.append(c)
    if len(candidate0) > K:
        candidate = candidate0
    elif len(candidate0) == K:
        break


ans = candidate0[0]
for c in candidate0[1:]:
    ans = ans & c
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
import numpy
N, K = map(int, input().split())
a = [int(i) for i in input().split()]
res = [0] + list(numpy.cumsum(a))


hq = []
heapq.heapify(hq)  # リストhqのheap化

for i in range(N):
    for j in range(i+1, N+1):
        heapq.heappush(hq, -(res[j]-res[i]))  # heap化されたリストhqに要素xを追加

m = 45
candidate = []
for i in range(N*(N+1)//2):
    a0 = -heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    digit = len(bin(a0))-2
    if digit == m:
        candidate.append(a0)
    else:
        m = digit
        candidate = [a0]
    if len(candidate) >= K:
        break
else:
    print(0)
    exit()

for i in range(m):
    candidate0 = []
    for c in candidate:
        if (c >> (m-i-1)) & 1 == 1:
            candidate0.append(c)
    if len(candidate0) > K:
        candidate = candidate0
    elif len(candidate0) == K:
        break
else:
    print(2**(m-1))
    exit()


ans = 2**16-1
for c in candidate0:
    ans = ans & c
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
import numpy
N, K = map(int, input().split())
a = [int(i) for i in input().split()]
res = [0] + list(numpy.cumsum(a))
# print(res)


hq = [0]
heapq.heapify(hq)  # リストhqのheap化

for i in range(N):
    for j in range(i+1, N+1):
        heapq.heappush(hq, -(res[j]-res[i]))  # heap化されたリストhqに要素xを追加

m = 45
candidate = []
for i in range(N*(N+1)//2+1):
    a0 = -heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    digit = len(bin(a0))-2
    if digit == m:
        candidate.append(a0)
    else:
        if len(candidate) >= K:
            break
        else:
            m = digit
            candidate = [a0]
else:
    print(0)
    exit()

for i in range(m):
    candidate0 = []
    for c in candidate:
        if (c >> (m-i-1)) & 1 == 1:
            candidate0.append(c)
    if len(candidate0) > K:
        candidate = candidate0
    elif len(candidate0) == K:
        break
else:
    print(2**(m-1))
    exit()


ans = 2**16-1
for c in candidate0:
    ans = ans & c
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
import numpy
N, K = map(int, input().split())
a = [int(i) for i in input().split()]
res = [0] + list(numpy.cumsum(a))
# print(res)


hq = [0]
heapq.heapify(hq)  # リストhqのheap化

for i in range(N):
    for j in range(i+1, N+1):
        heapq.heappush(hq, -(res[j]-res[i]))  # heap化されたリストhqに要素xを追加

m = 45
candidate = []
for i in range(N*(N+1)//2):
    a0 = -heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    digit = len(bin(a0))-2
    if digit == m:
        candidate.append(a0)
    else:
        if len(candidate) >= K:
            break
        else:
            m = digit
            candidate = [a0]
else:
    print(0)
    exit()

for i in range(m):
    candidate0 = []
    for c in candidate:
        if (c >> (m-i-1)) & 1 == 1:
            candidate0.append(c)
    if len(candidate0) > K:
        candidate = candidate0
    elif len(candidate0) == K:
        break
else:
    print(2**(m-1))
    exit()


ans = 2**16-1
for c in candidate0:
    ans = ans & c
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
import numpy
N, K = map(int, input().split())
a = [int(i) for i in input().split()]
res = [0] + list(numpy.cumsum(a))
# print(res)


hq = [0]
heapq.heapify(hq)  # リストhqのheap化

for i in range(N):
    for j in range(i+1, N+1):
        heapq.heappush(hq, -(res[j]-res[i]))  # heap化されたリストhqに要素xを追加

m = 45
candidate = []
for i in range(N*(N+1)//2):
    a0 = -heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    digit = len(bin(a0))-2
    if digit == m:
        candidate.append(a0)
    else:
        if len(candidate) >= K:
            break
        else:
            m = digit
            candidate = [a0]
else:
    print(0)
    exit()

for i in range(m):
    candidate0 = []
    for c in candidate:
        if (c >> (m-i-1)) & 1 == 1:
            candidate0.append(c)
    if len(candidate0) > K:
        candidate = candidate0
    elif len(candidate0) == K:
        break
else:
    print(2**(m-1))
    exit()

ans = 2**16-1
for c in candidate0:
    ans = ans & c
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
import numpy
N, K = map(int, input().split())
a = [int(i) for i in input().split()]
res = [0] + list(numpy.cumsum(a))
# print(res)


hq = [0]
heapq.heapify(hq)  # リストhqのheap化

for i in range(N):
    for j in range(i+1, N+1):
        heapq.heappush(hq, -(res[j]-res[i]))  # heap化されたリストhqに要素xを追加

m = 45
candidate = []
for i in range(N*(N+1)//2):
    a0 = -heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    digit = len(bin(a0))-2
    if digit == m:
        candidate.append(a0)
    else:
        if len(candidate) >= K:
            break
        else:
            m = digit
            candidate = [a0]
else:
    print(0)
    exit()

candidate0 = []
for i in range(m):
    for c in candidate:
        # print(i, c, c >> (m-i))
        if (c >> (m-i-1)) & 1 == 1:
            candidate0.append(c)
    # print(i, candidate0)
    if len(candidate0) > K:
        # candidate = candidate0
        candidate0 = []
    elif len(candidate0) == K:
        break
    else:
        candidate0 = []
else:
    print(2**(m-1))
    exit()

# print(candidate0)

ans = 2**16-1
for c in candidate0:
    ans = ans & c
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
import numpy
N, K = map(int, input().split())
a = [int(i) for i in input().split()]
res = [0] + list(numpy.cumsum(a))
# print(res)


hq = [0]
heapq.heapify(hq)  # リストhqのheap化

for i in range(N):
    for j in range(i+1, N+1):
        heapq.heappush(hq, -(res[j]-res[i]))  # heap化されたリストhqに要素xを追加

m = 45
candidate = []
for i in range(N*(N+1)//2):
    a0 = -heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    digit = len(bin(a0))-2
    if digit == m:
        candidate.append(a0)
    else:
        if len(candidate) >= K:
            break
        else:
            m = digit
            candidate = [a0]
else:
    print(0)
    exit()

candidate0 = []
for i in range(m):
    for c in candidate:
        # print(i, c, c >> (m-i))
        if (c >> (m-i-1)) & 1 == 1:
            candidate0.append(c)
    # print(i, candidate0)
    if len(candidate0) > K:
        candidate = candidate0
        candidate0 = []
    elif len(candidate0) == K:
        break
    else:
        candidate0 = []
else:
    print(2**(m-1))
    exit()

# print(candidate0)

ans = 2**16-1
for c in candidate0:
    ans = ans & c
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
import numpy
N, K = map(int, input().split())
a = [int(i) for i in input().split()]
res = [0] + list(numpy.cumsum(a))
# print(res)

hq = []
heapq.heapify(hq)  # リストhqのheap化

for i in range(N):
    for j in range(i+1, N+1):
        heapq.heappush(hq, -(res[j]-res[i]))

ans = -heapq.heappop(hq)
for _ in range(K-1):
    a = -heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    ans = ans & a
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
X = []
for l in range(N):
  r = l
  v = 0
  while r < N:
    v += A[r]
    X.append(v)
    r += 1
X.sort()
X=X[::-1]
ans = X[0]
for x in X[:K]:
  ans = (ans & x)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k = map(int,input().split())
a = list(map(int,input().split()))

q = [0]

for i in a:
    q.append(q[-1] + i)

#print(q)
data = []
append = data.append
for i in range(n+1):
    for j in range(i+1,n+1):
        append(q[j]-q[i])
data.sort(reverse=True)
print(data[k-1])

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
acc=[0]*(N+1)
tmp=0
for i in range(N):
    tmp+=A[i]
    acc[i+1]=tmp

nums=[]
for i in range(N):
    for j in range(i+1,N+1):
        n=acc[j]-acc[i]
        s=bin(n)[2:]
        s="0"*(30-len(s))+s
        nums.append(s)

ans=[]
for i in range(30):
    tmp=[]
    cnt=0
    tmp = [s for s in nums if s[i]=="1"]
    if len(tmp)>=K:
        ans.append("1")
        nums=tmp
    else:
        ans.append("0")

print(int("".join(ans),2))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
acc=[0]*(N+1)
tmp=0
for i in range(N):
    tmp+=A[i]
    acc[i+1]=tmp

nums=[]
for i in range(N):
    for j in range(i,N+1):
        n=acc[j]-acc[i]
        s=bin(n)[2:]
        s="0"*(30-len(s))+s
        nums.append(s)

ans=[]
for i in range(30):
    tmp=[]
    cnt=0
    for s in nums:
        if s[i]=="1":
            tmp.append(s)
            cnt+=1
    if cnt>=K:
        ans.append("1")
        nums=tmp
    else:
        ans.append("0")

print(int("".join(ans),2))

Submission status: Wrong Answer

Solution code:
#B問題
N,K = map(int,input().split())
A = list(map(int,input().split()))
rui = [0]

for i in range(N):
    if i == 0:
        rui.append(A[0])
    else:
        rui.append(rui[-1]+A[i])
    
bubun = []
for i in range(N):
    I = i
    for j in range(N-i):
        J = i+j+1
        bubun.append(rui[J]-rui[I])
    
bubun.sort(reverse=True)
for i in range(K):
    if i == 0:
        ans = bubun[0]
    else:
        ans&=bubun[i]
        
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
l = [0] + list(map(int, input().split()))
a = list()
for i in range(n):
  l[i+1] += l[i]
a = [l[j]-l[i] for j in range(i+1,n+1) for i in range(n)]
x = 0
for i in range(40,-1,-1):
  t = 2**i
  if sum(map(lambda y:(y&(t+x) == t+x),a)) >= k:
    x += t
print(x)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, k = li()
a = list(li())

cum = [0]
for ai in a:
    cum.append(cum[-1] + ai)

pool = []
for i in range(n+1):
    for j in range(i+1, n+1):
        pool.append(cum[j] - cum[i])

MAX_BIT = 32
ans = 0
for bit in range(MAX_BIT, -1, -1):
    new_pool = []
    for poli in pool:
        if poli & (1<<bit):
            new_pool.append(poli)

    if len(new_pool) >= k:
        ans += (1<<bit)
        pool = new_pool

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

cumA = [0] * (N + 1)
for i in range(1, N + 1):
    cumA[i] = cumA[i - 1] + A[i - 1]

beauty = []
for left in range(N):
    for right in range(left + 1, N + 1):
        b = cumA[right] - cumA[left]
        beauty.append(b)

beauty.sort(reverse=True)
ans = beauty[0]

for b in beauty[:K]:
    ans &= b

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

B = []
for l in range(N):
    b = 0
    for r in range(l, N):
        b += A[r]
        B.append(b)
B.sort(reverse=True)

def trans2(n):
    A = bin(n)
    return str(A[2:])

C = []
maxl = 0
for i, b in enumerate(B):
    l = len(trans2(b))
    if i+1 <= K:
        maxl = l
    if i+1 > K and maxl != l:
        break
    C.append(trans2(b))

OK = [1 for _ in range(len(C))]

ans = 0
for l in range(maxl-1, -1, -1):
    update = []
    for i, c in enumerate(C):
        if c[-l-1] == '0':
            update.append(i)
            OK[i] = 0
    oks = sum(OK)
    if oks < K:
        for u in update:
            OK[u] = 1
    else:
        ans += 2**l
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))
x = 0
for i in range(40,-1,-1):
  t = 2**i
  if sum(1 for p in a if p&(t+x)) >= k:
    x += t
print(x)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

ruiseki = [0] * (n + 1)
for i in range(n):
    ruiseki[i+1] = ruiseki[i] + a[i]

li = []
for i in range(n):
    for j in range(i, n):
        tmp = format(ruiseki[j + 1] - ruiseki[i], '031b')
        li.append(tmp)

for i in range(31):
    cnt = 0
    new_li = []
    for j in range(len(li)):
        if li[j][i] == "1":
            new_li.append(li[j])
            cnt += 1
    if cnt >= k:
        li = new_li[0:]

ans = 2**31 -1
for i in range(k):
    ans = ans & int(li[i], 2)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

ruiseki = [0] * (n + 1)
for i in range(n):
    ruiseki[i+1] = ruiseki[i] + a[i]

li = []
for i in range(n):
    for j in range(i, n):
        tmp = format(ruiseki[j + 1] - ruiseki[i], '030b')
        li.append(tmp)

for i in range(30):
    cnt = 0
    new_li = []
    for j in range(len(li)):
        if li[j][i] == "1":
            new_li.append(li[j])
            cnt += 1
    if cnt >= k:
        li = new_li[0:]

ans = 2**31 -1
for i in range(k):
    ans = ans & int(li[i], 2)
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=[]
for i in range(n):
    c=0
    for j in a[i:]:
        c+=j
        l.append(c)
t=0
for i in range(40,0,-1):
    s=t+2**i
    c=0
    for j in l:
        if j&s==s:
            c+=1
    else:
        if k<=c:
            t=s
print(t)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=[]
for i in range(n):
    c=0
    for j in a[i:]:
        c+=j
        l.append(c)
t=0
for i in range(40,0,-1):
    s=t+2**i
    c=0
    for j in l[bl(l,t):]:
        if j&s==s:
            c+=1
    else:
        if k<=c:
            t=s
print(t)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from collections import deque
import itertools
from itertools import permutations
import sys

import bisect
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
YNeos='YNeos'
GYN=['Yes','trumpet']
mo=10**9+7
imp='IMPOSSIBLE'

n,k=MI()
a=LI()
A=[0]
for i in a:
    A+=[A[-1]+i]
b=[]
for i in range(n+1):
    for j in range(i+1,n+1):
        b+=[A[j]-A[i]]
        
c=sorted(b)#[-k:]
ans=0
i=0
i2=1
while i2<c[-1]:
    ans+=i2 if sum([j&(ans+i2)>0 for j in c])>=k else 0
    #print(i2,sum([j>>i&1 for j in c]))
    i2*=2
    i+=1
    
print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from collections import deque
import itertools
from itertools import permutations
import sys

import bisect
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
YNeos='YNeos'
GYN=['Yes','trumpet']
mo=10**9+7
imp='IMPOSSIBLE'

n,k=MI()
a=LI()
A=[0]
for i in a:
    A+=[A[-1]+i]
b=[]
for i in range(n+1):
    for j in range(i+1,n+1):
        b+=[A[j]-A[i]]
        
c=sorted(b)[-k:]
ans=0
i=0
i2=1
while i2<c[-1]:
    ans+=i2 if sum([j&(ans+i2)>0 for j in c])>=k else 0
    #print(i2,sum([j>>i&1 for j in c]))
    i2*=2
    i+=1
    
print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from collections import deque
import itertools
from itertools import permutations
import sys

import bisect
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
YNeos='YNeos'
GYN=['Yes','trumpet']
mo=10**9+7
imp='IMPOSSIBLE'

n,k=MI()
a=LI()
A=[0]
for i in a:
    A+=[A[-1]+i]
b=[]
for i in range(n+1):
    for j in range(i+1,n+1):
        b+=[A[j]-A[i]]
        
c=sorted(b)[-k:]
ans=0
i=0
i2=1
while i2<c[-1]*2:
    ans+=i2 if sum([j>>i&1 for j in c])==k else 0
    #print(i2,sum([j>>i&1 for j in c]))
    i2*=2
    i+=1
    
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
vA = list(map(int, input().split()))

# 累積和
vC = [0,]
for a in vA:
    vC.append(a + vC[-1])

# 部分列の和 (美しさ)
vB = []
for i in range(len(vC)):
    vB.extend([vC[i+j+1] - vC[i] for j in range(N-i)])

# 最上位bitが何桁目かを取得
blenB = max(vB).bit_length()

# K個に満たない上位bitは最終的に残らないので除去する
# 上からK個以上あるものを決めていく
x = 0
for i in reversed(range(1, blenB+1)):
    x_new = x + (1<<i)
    if sum((x_new & b) == x_new for b in vB) >= K:
        x = x_new

print(x)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
vA = list(map(int, input().split()))

# 累積和
vC = [0,]
for a in vA:
    vC.append(a + vC[-1])

# 部分列の和 (美しさ)
vB = []
for i in range(len(vC)):
    vB.extend([vC[i+j+1] - vC[i] for j in range(N-i)])

# 最上位bitが何桁目かを取得
blenB = max(vB).bit_length()

# K個に満たない上位bitは最終的に残らないので除去する
reduc = 1
for i in reversed(range(1, blenB+1)):
    if sum((1<<i & b) > 0 for b in vB) >= K:
        reduc = i+1
        break
vB = [((1<<reduc) - 1) & b for b in vB]

# dp[i][k] := i番目まででk個取ったときの最適値
INF = (1<<63) - 1
dp = [[0,] * (K+1)]
dp[0][0] = INF
for b in vB:
    dp.append([max(dp[-1][k-1] & b, dp[-1][k]) for k in range(K+1)])

print(dp[-1][K])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
vA = list(map(int, input().split()))

# 累積和
vC = [0,]
for a in vA:
    vC.append(a + vC[-1])

# 部分列の和 (美しさ)
vB = []
for i in range(len(vC)):
    vB.extend([vC[i+j+1] - vC[i] for j in range(N-i)])

# 降順ソート
vB.sort()
vB = vB[::-1]

# dp[i][k] := i番目まででk個取ったときの最適値
INF = (1<<63) - 1
dp = [[0,] * (K+1)]
dp[0][0] = INF
for b in vB:
    dp.append([max(dp[-1][k-1] & b, dp[-1][k]) for k in range(K+1)])

print(dp[-1][K])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
vA = list(map(int, input().split()))

# 累積和
vC = [0,]
for a in vA:
    vC.append(a + vC[-1])

# 部分列の和 (美しさ)
vB = []
for i in range(len(vC)):
    vB.extend([vC[i+j+1] - vC[i] for j in range(N-i)])

# 降順ソート
vB.sort()
vB = vB[::-1]

res = vB[0]
for i in range(K):
    res &= vB[i]
print(res)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
alist=list(map(int,input().split()))

sum_list=[]
for i in range(N):
  s=0
  for j in range(i,N):
    s+=alist[j]
    sum_list.append(s)
    
sum_list.sort(reverse=True)
#print(sum_list)

answer=sum_list[0]
for i in range(1,K):
  answer&=sum_list[i]
  
print(answer)

Submission status: Wrong Answer

Solution code:
import copy
N,K=list(map(int,input().split()))
a=list(map(int,input().split()))

num=0
a_sum=[0]
for i in range(N):
  num+=a[i]
  a_sum.append(num)
  

print(a_sum)

a_mat=[[0 for i in range(N)] for j in range(N)]
non_zero=[]
for i in range(N):
  for j in range(i,N):
    a_mat[i][j] = a_sum[j+1]-a_sum[i]
    non_zero.append([i,j])

a_mat2=copy.deepcopy(a_mat)

maxbit=1
while True:
  if a_sum[N]<2**maxbit and a_sum[N]>=2**(maxbit-1): 
    break
  else:
    maxbit+=1
maxnum=0
num_rest=int(N*(N+1)/2)
num_rest_now=int(N*(N+1)/2)
for bit in range(maxbit):
  non_zero2=[]
  for i, j in non_zero:
    if a_mat[i][j]&(2**(maxbit-bit-1)) == 0 and a_mat[i][j]!=0:
      num_rest_now-=1
      a_mat2[i][j]=0
    else:
      non_zero2.append([i,j])
  #print(a_mat)
  #print(num_rest_now)
  if num_rest_now >= K:
    maxnum+=2**(maxbit-bit-1)
    a_mat=copy.deepcopy(a_mat2)
    num_rest=num_rest_now
    non_zero=copy.deepcopy(non_zero2)
  else:
    a_mat2=copy.deepcopy(a_mat)
    num_rest_now=num_rest
    
  
  
print(maxnum)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    from itertools import accumulate

    n, k = map(int, input().split())
    a = list(accumulate([0] + list(map(int, input().split()))))
    bit_groups = list()

    for j in range(1, n + 1):
        for i in range(j, n + 1):
            bit = bin(a[i] - a[j - 1])[2:]
            length = len(bit)

            if length < 40:
                bit = '0' * (40 - length) + bit

            bit_groups.append(bit)

    ans = 0
    digit_max = 40

    for i in range(digit_max):
        count = 0

        for bit_group in bit_groups:
            if int(bit_group, 2) >= ans and bit_group[i] == '1':
                count += 1

        if count >= k:
            ans += 2 ** ((digit_max - 1) - i)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# N的に全探索できるのでそうする
from functools import reduce
n, k = map(int, input().split())
arr = list(map(int, input().split()))

res = []

for i in range(n):
    for j in range(i, n+1):
        if i == j:
            continue
        res.append(sum(arr[i:j]))

res = list(sorted(res, reverse=True))[:k]
ans = reduce(lambda x, y: x & y, res)
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
arr=list(map(int,input().split()))
cand=[]
l=41
s=format(arr[0],'b')
cand.append('0'*(l-len(s))+s)
for i in range(n-1):
  arr[i+1]+=arr[i]
  s=format(arr[i+1],'b')
  cand.append('0'*(l-len(s))+s)
for i in range(n):
  for j in range(i+1,n):
    s=format(arr[j]-arr[i],'b')
    cand.append('0'*(l-len(s))+s)
check=''
w=len(cand)
for i in range(41):
  cnt=0
  for j in range(w):
    if cand[j][:i]!=check:
      continue
    if cand[j][i]=='1':
      cnt+=1
  if cnt>=k:
    check+='1'
  else:
    check+='0'
ans=0
for i in range(41):
  if check[i]=='1':
    ans+=2**(40-i)
print(ans)

Submission status: Wrong Answer

Solution code:
N, K =map(int, input().split())
a = list(map(int, input().split()))
cumsum = [0]
for i in range(N):
    cumsum.append( a[i] + cumsum[i] )
#print("{}".format(cumsum))

beauty = []
for l in range(N + 1):
    for r in range(l + 1, N + 1):
        beauty.append(cumsum[r] - cumsum[l])
beauty.sort()
#print("{}".format(beauty))

max = 0
for shift in range(4, 0, -1):
    mask = 1 << shift
    count = 0
#    print("{} {}".format(shift,beauty))
    for i in range(len(beauty)-1,-1,-1):
#        print("{} {}".format(i,beauty[i]))
        if (beauty[i] & mask) == 0:
            continue
        count+=1
    if count >= K:
#        print("{} {} {}".format(shift,max,mask))
        max |= mask;
#        print("{} {} {}".format(shift,max,mask))
        tmp = []
        for i in range(len(beauty) - 1, -1, -1):
            if ((beauty[i] & mask) == 0):
                continue
            tmp.append(beauty[i])
        beauty.clear()
        for i in range(len(tmp)):
            beauty.append(tmp[i])
print(max)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
B=[]
for i in range(1,N+1):
    for j in range(N-i+1):
        B.append(A[i+j]-A[j])
B.sort(reverse=True)
m=40
x=0
for t in range(m,0,-1):
    res=0
    for a in B:
        if ((x+1<<(t-1))&a)==(x+1<<(t-1)):
            res+=1
        if res>=K:
            x+=1<<(t-1)
            break
print(x)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
d2={i:[] for i in range(40)}
d=set()
for i in range(n):
    tmp=a[i]
    b=bin(tmp)[2:].zfill(40)
    d.add(b)
    for j in range(i+1,n):
        tmp+=a[j]
        b=bin(tmp)[2:].zfill(40)
        d.add(b)
for x in d:
    for i in range(40):
        if x[i]=='1':
            d2[i].append(int('0b'+x,2))
for i in range(40):
    if len(d2[i])>=k:
        l=d2[i]
        l.sort()
        x=l.pop()
        for j in range(k-1):
            x&=l.pop()
        print(x)
        break

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
d=set()
for i in range(n):
    for j in range(i,n):
        d.add(sum(a[i:j+1]))
d=list(d)
d.sort()
x=d.pop()
for i in range(k-1):
    x&=d.pop()
print(x)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))

l = []
for i in range(N):
    s = 0
    for j in range(i,N):
        s += a[j]
        l.append(s)

l = sorted(l)
ans = l[-1]
for i in range(1,K):
    ans &= l[-i-1]
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))

l = []
for i in range(N):
    s = 0
    for j in range(i,N):
        s += a[j]
        l.append(s)

l = sorted(set(l))
ans = l[-1]
for i in range(1,K):
    ans &= l[-i-1]
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate, combinations
N, K = map(int, input().split())
A = list(map(int, input().split()))

SA = list(accumulate(A)) + [0]
B = A[:]

for l, r in combinations(range(N), 2):
    B.append(SA[r] - SA[l-1])

ans = 0
for i in range(33, -1, -1):
    ans *= 2
    B1 = [b for b in B if 2**i & b]
    if len(B1) >= K:
        ans += 1
        B = B1[:]

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N,K=map(int,input().split())
A=list(map(int,input().split()))

data=[]
for i in range(N):
    now=0
    for j in range(i,N):
        now+=A[j]
        data.append(now)
data.sort()
ans=0
for i in range(30,-1,-1):
    s=pow(2,i)
    idx=bisect.bisect_left(data,s)
    if len(data)-idx>=K:
        ans+=s
        data=[d-s for d in data[idx:]]
    else:
        data=[d for d in data[:idx]]+[d-s for d in data[idx:]]
        data.sort()
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N,K=map(int,input().split())
A=list(map(int,input().split()))

data=[]
for i in range(N):
    now=0
    for j in range(i,N):
        now+=A[j]
        data.append(now)
data.sort()
ans=0
for i in range(30,-1,-1):
    s=pow(2,i)
    idx=bisect.bisect_left(data,s)
    if len(data)-idx>=K:
        ans+=s
        data=[d-s for d in data[idx:]]
    else:
        data=[d for d in data[:idx]]+[d-s for d in data[idx:]]
print(ans)

Submission status: Wrong Answer

Solution code:
import functools
import operator
n, k = map(int, input().split())
a = list(map(int, input().split()))
ll = []
for x in range(n):
    [ll.append(a[x:t+1]) for t in range(x, n)]
print(functools.reduce(operator.and_, sorted(list(map(sum, ll)), reverse=True)[0:k]))

Submission status: Wrong Answer

Solution code:

from collections import defaultdict

def search(binaries, K):
    max_b = max(binaries)
    max_bit = 0
    while max_b > 0:
        max_b = max_b >>1
        max_bit += 1

    ans = 0
    for i in reversed(range(max_bit + 1)):
        a = ans + (1 << i)
        binareis = list(filter(lambda b: (b & a) == a, binaries))
        if len(binaries) >= K:
            ans += 1 << i
        else:
            break
    return ans

def main():
    N, K = list(map(int, input().split()))
    a = list(map(int, input().split()))

    # make binaries
    binaries = []
    for i in range(N):
        for j in range(i, N):
            binaries.append(sum(a[i:j+1]))

    print(search(binaries, K))


main()