Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Java

# import sys
# rop=[]
# for line in sys.stdin:
#     rop.append(line.strip())
# for i in rop:
#     print(i)
    
def ratatouille():
    N, P = map(int, input().strip().split())
    R = list(map(int, input().strip().split()))
    Q = []
    for _ in range(N):
        Q.append(list(map(int, input().strip().split())))
    # print(Q,R)
    choices = []
    for i in range(N):
        for j in range(P):
            q, r = Q[i][j], R[i]
            lower = max(1, (10 * q + 11 * r - 1) // (11 * r))
            upper = (10 * q) // (9 * r)
            if lower > upper: continue
            choices.append((lower, False, i, q))
            choices.append((upper, True, i, q))
    choices.sort()

    count = 0
    quantities = [[] for _ in range(N)]
    for (_, is_upper, i, q) in choices:
        if is_upper:
            if q in quantities[i]:
                quantities[i].remove(q)
        else:
            quantities[i].append(q)
            if all(quantities):
                count += 1
                for j in range(N):
                    del quantities[j][0]
    return count

for case in range(1):
    print(ratatouille())
Source by # #
 
PREVIOUS NEXT
Tagged: #Java
ADD COMMENT
Topic
Name
4+5 =