1945D - Seraphim the Owl - CodeForces Solution


greedy

Please click on ads to support us..

Python Code:


import heapq
from math import pi,sqrt,ceil,floor,log2,log10
from collections import deque,defaultdict,Counter
from sys import setrecursionlimit
setrecursionlimit(1_000_000)


def gcd(a,b):
    while(b):
        a,b = b,a % b

    return a

def lcm(a,b):
    return a * b // gcd(a,b)


def minput():
    return map(int,input().split())

def linput():
    return list(map(int,input().split()))


MOD = int(1e9) + 7
sz = int(1e5) + 5
INT_MAX = float('inf')


def solve():
    n,m = minput()

    arr = [linput() for _ in range(2)]

    sum = 0
    res = INT_MAX

    for i in range(n - 1,-1,-1):
        if(i + 1 <= m):
            res = min(res,sum + arr[0][i])

        sum += min(arr[0][i],arr[1][i])

    print(res)




def main():
    t = int(input())

    for _ in range(t):
        solve()


if __name__ == '__main__':
    main()


Comments

Submit
0 Comments
More Questions

535A - Tavas and Nafas
581A - Vasya the Hipster
1537B - Bad Boy
1406B - Maximum Product
507B - Amr and Pins
379A - New Year Candles
1154A - Restoring Three Numbers
750A - New Year and Hurry
705A - Hulk
492B - Vanya and Lanterns
1374C - Move Brackets
1476A - K-divisible Sum
1333A - Little Artem
432D - Prefixes and Suffixes
486A - Calculating Function
1373B - 01 Game
1187A - Stickers and Toys
313B - Ilya and Queries
579A - Raising Bacteria
723A - The New Year Meeting Friends
302A - Eugeny and Array
1638B - Odd Swap Sort
1370C - Number Game
1206B - Make Product Equal One
131A - cAPS lOCK
1635A - Min Or Sum
474A - Keyboard
1343A - Candies
1343C - Alternating Subsequence
1325A - EhAb AnD gCd