""" Google Code Jam Farewell Round C - Problem B Author : chaotic_iak Language: PyPy (Python 3.9.10) """ ################################################### SOLUTION OWN_TEST = False import heapq, random def initialize_solution(): ... def main(): V,M = read() if not OWN_TEST else [100000, 100000] P = read() if not OWN_TEST else [random.randrange(1, 10**9) for _ in range(100000)] D = read() if not OWN_TEST else [random.randrange(1, 10**9) for _ in range(100000)] X = read() if not OWN_TEST else [random.randrange(-10**9, 10**9) for _ in range(100000)] dest_right = [] pick_left = [] for i in range(V): if P[i] < D[i]: dest_right.append(D[i]) else: pick_left.append((P[i], D[i])) dest_right.sort() pick_left.sort() dest_left = [] ans = [] record = 0 curr = 0 dr_got = 0 pl_got = 0 for x in X: ans.append(0) old = curr if x > 0: curr += x while dr_got < len(dest_right) and dest_right[dr_got] <= curr: ans[-1] += 1 dr_got += 1 while pl_got < len(pick_left) and pick_left[pl_got][0] <= curr: heapq.heappush(dest_left, -pick_left[pl_got][1]) pl_got += 1 record = max(record, curr) else: curr += x while dest_left and -dest_left[0] >= curr: heapq.heappop(dest_left) ans[-1] += 1 write(*ans) ############################################### PROBLEM TYPE HAS_TESTCASES = True INTERACTIVE = False INTERACTIVE_WRONG_ANSWER = "" #################################################### HELPERS import sys def read_str(): ipt = input().strip() if INTERACTIVE and ipt == INTERACTIVE_WRONG_ANSWER: sys.exit() return ipt def read(mapping=int): ipt = input().strip() if INTERACTIVE and ipt == INTERACTIVE_WRONG_ANSWER: sys.exit() return list(map(mapping, ipt.split())) def write_str(obj, end="\n"): global OUTPUT OUTPUT.append(obj + end) def write(*obj, sep=" ", end="\n"): global OUTPUT OUTPUT.append(sep.join(map(str, obj)) + end) def flush(): global OUTPUT print("".join(OUTPUT), end="", flush=True) OUTPUT = [] def solve_testcase(): result = main() if result is not None: write(result) OUTPUT = [] initialize_solution() if HAS_TESTCASES: TOTAL_CASES = int(input()) else: TOTAL_CASES = 1 for CASE_NUMBER in range(TOTAL_CASES): write("Case #" + str(CASE_NUMBER+1) + ": ", end="") solve_testcase() flush() READ_FROM_FILE = ""