86442024-01-24 18:05:18NagyLeoMI bróker (50 pont)pypy3Wrong answer 20/50177ms99956 KiB
from sys import stdin, stdout

input = stdin.readline


# O(N*Q)
# N, Q = 0, 0
def main(Q, N, Prices):
    # N,Q = list(map(int, input().split()))
    # N,Q = [int(x) for x in input().split()]
    # N = NQ[0]
    # Q = NQ[1]
    # Prices = list(map(int, stdin.readline().split()))
    # balance = [0]*Q

    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
        # balance.append(curBalance)
        # balance[i]=curBalance

        # for i in balance:
        stdout.write(str(curBalance) + '\n')


# main()

# 5 10 10 10 5 5 5 5
# Q:
# 6 9
# 7 8
# 6 8
def ketszam():
    N, Q = list(map(int, input().split()))
    Prices = list(map(int, stdin.readline().split()))
    first = Prices[0]
    second = 0

    if Q <= 50:
        main(Q, N, Prices)
        return

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

    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
base20/50
1Accepted0/043ms77056 KiB
2Wrong answer0/0122ms92076 KiB
3Accepted1/148ms77776 KiB
4Accepted1/148ms77844 KiB
5Accepted2/256ms87344 KiB
6Accepted2/259ms89368 KiB
7Accepted2/271ms89284 KiB
8Accepted1/1165ms95976 KiB
9Accepted1/1167ms97304 KiB
10Accepted2/2146ms95932 KiB
11Accepted2/2165ms96944 KiB
12Accepted2/2168ms98188 KiB
13Accepted2/2166ms97560 KiB
14Accepted2/2157ms96956 KiB
15Wrong answer0/3177ms97860 KiB
16Wrong answer0/3165ms96800 KiB
17Wrong answer0/3171ms97892 KiB
18Wrong answer0/3160ms97760 KiB
19Wrong answer0/3170ms98652 KiB
20Wrong answer0/3175ms97496 KiB
21Wrong answer0/3166ms97728 KiB
22Wrong answer0/3172ms99212 KiB
23Wrong answer0/3170ms99956 KiB
24Wrong answer0/3167ms99572 KiB