86432024-01-24 17:55:15NagyLeoMI bróker (50 pont)pypy3Hibás válasz 14/50180ms98828 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()
RészfeladatÖsszpontTesztVerdiktIdőMemória
base14/50
1Hibás válasz0/048ms76476 KiB
2Hibás válasz0/0128ms92456 KiB
3Elfogadva1/148ms77784 KiB
4Elfogadva1/148ms78288 KiB
5Hibás válasz0/250ms87036 KiB
6Hibás válasz0/254ms87628 KiB
7Hibás válasz0/259ms88084 KiB
8Elfogadva1/1158ms96420 KiB
9Elfogadva1/1165ms95020 KiB
10Elfogadva2/2143ms95524 KiB
11Elfogadva2/2173ms96208 KiB
12Elfogadva2/2155ms96648 KiB
13Elfogadva2/2174ms97808 KiB
14Elfogadva2/2153ms95848 KiB
15Hibás válasz0/3158ms98472 KiB
16Hibás válasz0/3149ms95464 KiB
17Hibás válasz0/3180ms98360 KiB
18Hibás válasz0/3172ms97276 KiB
19Hibás válasz0/3165ms97028 KiB
20Hibás válasz0/3162ms97248 KiB
21Hibás válasz0/3165ms98144 KiB
22Hibás válasz0/3158ms98828 KiB
23Hibás válasz0/3165ms98232 KiB
24Hibás válasz0/3175ms98280 KiB