86422024-01-24 17:51:18NagyLeoMI bróker (50 pont)pypy3Wrong answer 11/50173ms98684 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:
            if lo > second and Prices[0] == second:
                stdout.write(str(-second) + '\n')
            else:
                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/050ms76852 KiB
2Wrong answer0/0144ms92816 KiB
3Accepted1/143ms77524 KiB
4Accepted1/141ms77488 KiB
5Wrong answer0/254ms86800 KiB
6Wrong answer0/250ms87392 KiB
7Wrong answer0/250ms88244 KiB
8Wrong answer0/1165ms97384 KiB
9Accepted1/1160ms95204 KiB
10Accepted2/2135ms95392 KiB
11Accepted2/2158ms95276 KiB
12Accepted2/2150ms96076 KiB
13Accepted2/2173ms96808 KiB
14Wrong answer0/2166ms96240 KiB
15Wrong answer0/3164ms98684 KiB
16Wrong answer0/3138ms95724 KiB
17Wrong answer0/3159ms98052 KiB
18Wrong answer0/3156ms96712 KiB
19Wrong answer0/3152ms96472 KiB
20Wrong answer0/3145ms96656 KiB
21Wrong answer0/3158ms97440 KiB
22Wrong answer0/3156ms98528 KiB
23Wrong answer0/3153ms97352 KiB
24Wrong answer0/3165ms97884 KiB