86332024-01-24 09:54:43lacitoMI bróker (50 pont)pypy3Accepted 50/50294ms143732 KiB
from sys import stdin, stdout

def main():
    MAXA = 501
    ans = [[0] * 512 for _ in range(512)]

    _, q = map(int, stdin.readline().split())
    a = list(map(int, stdin.readline().split()))
    for v in range(1, MAXA):
        e_min = MAXA
        for x in a:
            if (x <= v):
                ans[v][v + 1] -= x
                ans[v][e_min] += x
                e_min = v + 1
            elif (x >= e_min):
                ans[v][e_min] += x
                ans[v][x + 1] -= x
                e_min = x + 1
        for e in range(v + 1, MAXA):
            ans[v][e] += ans[v][e - 1]
    
    profit = [0] * q
    for i, ve in enumerate(stdin.readlines()):
        v, e = map(int, ve.split())
        profit[i] = ans[v][e]
    
    stdout.write('\n'.join(str(p) for p in profit) + '\n')
    
main()
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/057ms90276 KiB
2Accepted0/0230ms119052 KiB
3Accepted1/159ms92112 KiB
4Accepted1/170ms91680 KiB
5Accepted2/271ms92812 KiB
6Accepted2/2171ms93700 KiB
7Accepted2/2162ms93984 KiB
8Accepted1/1231ms137332 KiB
9Accepted1/1256ms138568 KiB
10Accepted2/2279ms143512 KiB
11Accepted2/2284ms139796 KiB
12Accepted2/2293ms142720 KiB
13Accepted2/2294ms141596 KiB
14Accepted2/2287ms140636 KiB
15Accepted3/3287ms142404 KiB
16Accepted3/3268ms142556 KiB
17Accepted3/3287ms142320 KiB
18Accepted3/3287ms142204 KiB
19Accepted3/3287ms143112 KiB
20Accepted3/3287ms142772 KiB
21Accepted3/3259ms143308 KiB
22Accepted3/3284ms142624 KiB
23Accepted3/3268ms142696 KiB
24Accepted3/3275ms143732 KiB