86412024-01-24 17:44:59NagyLeoMI bróker (50 pont)pypy3Wrong answer 11/50159ms99308 KiB
from sys import stdin, stdout
input=stdin.readline

def main():
    N,Q = list(map(int, input().split()))
    # N,Q = [int(x) for x in input().split()]

    Prices = list(map(int, stdin.readline().split()))

    for i in range(Q):
        isHolding = False
        curBalance = 0
        lo,hi = list(map(int, stdin.readline().split()))
        for f in Prices:
            if not isHolding:
                if lo >= f:
                    curBalance -= f
                    isHolding = True
            elif hi <= f:
                curBalance += f
                isHolding = False

        stdout.write(str(curBalance) + '\n')


#main()

def ketszam():
    N, Q = list(map(int, input().split()))
    Prices = list(map(int, stdin.readline().split()))
    first = Prices[0]
    second = 0

    for i in Prices:  # range(1,len(Prices)))
        if i != first:
            second = i
            break

    if second < first:
        second, first = first, second

    fourth = False
    fourthBalance = 0
    for i in range(Q):
        lo, hi = list(map(int, stdin.readline().split()))
        if lo < first:
            stdout.write('0\n')
        elif hi > second:
            stdout.write(str(-first) + '\n')
        else:
            if fourth == False:
                fourth = True
                isHolding = False
                curBalance = 0
                for f in Prices:
                    if not isHolding:
                        if lo >= f:
                            curBalance -= f
                            isHolding = True
                    elif hi <= f:
                        curBalance += f
                        isHolding = False

                stdout.write(str(curBalance) + '\n')
                fourthBalance = curBalance
            else:
                stdout.write(str(fourthBalance) + '\n')


ketszam()
SubtaskSumTestVerdictTimeMemory
base11/50
1Wrong answer0/041ms76440 KiB
2Wrong answer0/0127ms91536 KiB
3Accepted1/143ms77796 KiB
4Accepted1/141ms78004 KiB
5Wrong answer0/246ms87148 KiB
6Wrong answer0/246ms87592 KiB
7Wrong answer0/250ms87944 KiB
8Wrong answer0/1143ms97268 KiB
9Accepted1/1150ms94948 KiB
10Accepted2/2136ms95512 KiB
11Accepted2/2159ms95644 KiB
12Accepted2/2146ms96996 KiB
13Accepted2/2153ms96856 KiB
14Wrong answer0/2143ms95652 KiB
15Wrong answer0/3155ms99308 KiB
16Wrong answer0/3137ms94708 KiB
17Wrong answer0/3156ms97144 KiB
18Wrong answer0/3151ms95424 KiB
19Wrong answer0/3148ms96556 KiB
20Wrong answer0/3141ms96092 KiB
21Wrong answer0/3153ms96724 KiB
22Wrong answer0/3153ms97960 KiB
23Wrong answer0/3141ms96204 KiB
24Wrong answer0/3158ms97020 KiB