Submission #66118025


Source Code Expand

Copy
from collections import deque
import sys
def sliding_window_max_sum(A, k):
dq = deque()
total = 0
for i in range(len(A)):
while dq and dq[0] <= i - k:
dq.popleft()
while dq and A[dq[-1]] <= A[i]:
dq.pop()
dq.append(i)
if i >= k - 1:
total += A[dq[0]]
return total
def main():
input = sys.stdin.read
data = list(map(int, input().split()))
N = data[0]
A = data[1:]
for k in range(1, N + 1):
print(sliding_window_max_sum(A, k))
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
from collections import deque
import sys
def sliding_window_max_sum(A, k):
    dq = deque()
    total = 0
    for i in range(len(A)):
        while dq and dq[0] <= i - k:
            dq.popleft()
        while dq and A[dq[-1]] <= A[i]:
            dq.pop()
        dq.append(i)
        if i >= k - 1:
            total += A[dq[0]]
    return total
def main():
    input = sys.stdin.read
    data = list(map(int, input().split()))
    N = data[0]
    A = data[1:]
    for k in range(1, N + 1):
        print(sliding_window_max_sum(A, k))
if __name__ == "__main__":
    main()

Submission Info

Submission Time
Task F - Sums of Sliding Window Maximum
User SqRooti
Language Python (CPython 3.11.4)
Score 0
Code Size 596 Byte
Status TLE
Exec Time 2211 ms
Memory 31868 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 550
Status
AC × 3
AC × 27
TLE × 10
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt
All 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-small-01.txt, 01-small-02.txt, 01-small-03.txt, 01-small-04.txt, 01-small-05.txt, 01-small-06.txt, 01-small-07.txt, 01-small-08.txt, 01-small-09.txt, 01-small-10.txt, 01-small-11.txt, 01-small-12.txt, 01-small-13.txt, 01-small-14.txt, 01-small-15.txt, 01-small-16.txt, 01-small-17.txt, 01-small-18.txt, 01-small-19.txt, 01-small-20.txt, 01-small-21.txt, 01-small-22.txt, 01-small-23.txt, 01-small-24.txt, 02-large-01.txt, 02-large-02.txt, 02-large-03.txt, 02-large-04.txt, 02-large-05.txt, 02-large-06.txt, 02-large-07.txt, 02-large-08.txt, 02-large-09.txt, 02-large-10.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 10 ms 9340 KiB
00-sample-02.txt AC 10 ms 9308 KiB
00-sample-03.txt AC 10 ms 9368 KiB
01-small-01.txt AC 10 ms 9344 KiB
01-small-02.txt AC 10 ms 9308 KiB
01-small-03.txt AC 10 ms 9360 KiB
01-small-04.txt AC 10 ms 9296 KiB
01-small-05.txt AC 10 ms 9308 KiB
01-small-06.txt AC 10 ms 9304 KiB
01-small-07.txt AC 10 ms 9344 KiB
01-small-08.txt AC 10 ms 9392 KiB
01-small-09.txt AC 10 ms 9344 KiB
01-small-10.txt AC 10 ms 9340 KiB
01-small-11.txt AC 10 ms 9364 KiB
01-small-12.txt AC 10 ms 9284 KiB
01-small-13.txt AC 11 ms 9320 KiB
01-small-14.txt AC 10 ms 9380 KiB
01-small-15.txt AC 557 ms 9432 KiB
01-small-16.txt AC 723 ms 9512 KiB
01-small-17.txt AC 540 ms 9524 KiB
01-small-18.txt AC 707 ms 9496 KiB
01-small-19.txt AC 705 ms 9564 KiB
01-small-20.txt AC 707 ms 9552 KiB
01-small-21.txt AC 721 ms 9528 KiB
01-small-22.txt AC 715 ms 9624 KiB
01-small-23.txt AC 674 ms 9468 KiB
01-small-24.txt AC 721 ms 9568 KiB
02-large-01.txt TLE 2211 ms 31604 KiB
02-large-02.txt TLE 2208 ms 31724 KiB
02-large-03.txt TLE 2208 ms 12816 KiB
02-large-04.txt TLE 2208 ms 31484 KiB
02-large-05.txt TLE 2208 ms 31568 KiB
02-large-06.txt TLE 2208 ms 31496 KiB
02-large-07.txt TLE 2208 ms 31804 KiB
02-large-08.txt TLE 2208 ms 31656 KiB
02-large-09.txt TLE 2208 ms 31868 KiB
02-large-10.txt TLE 2208 ms 31500 KiB


2025-08-22 (Fri)
02:52:57 +09:00