QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#505222#7339. A Really Odd SequenceyundaehyuckAC ✓1991ms299168kbPython3940b2024-08-04 22:39:072024-08-04 22:39:09

Judging History

This is the latest submission verdict.

  • [2024-08-04 22:39:09]
  • Judged
  • Verdict: AC
  • Time: 1991ms
  • Memory: 299168kb
  • [2024-08-04 22:39:07]
  • Submitted

answer

import sys
input = sys.stdin.read

def main():
    data = input().split()
    index = 0
    T = int(data[index])
    index += 1
    results = []
    
    for _ in range(T):
        n = int(data[index])
        index += 1
        a = [0] * (n + 1)
        
        for i in range(1, n + 1):
            a[i] = int(data[index])
            index += 1
            a[i] += a[i - 1]
        
        ans = -10**18
        min1 = 0
        min2 = 10**18
        
        for i in range(1, n + 1):
            if i % 2 == 1:
                min1 = min(min1, a[i - 1])
            else:
                min2 = min(min2, a[i - 1])
            
            if i % 2 == 1:
                ans = max(ans, a[i] - min1)
            else:
                ans = max(ans, a[i] - min2)
        
        results.append(ans)
    
    for result in results:
        print(result)

if __name__ == "__main__":
    main()

詳細信息

Test #1:

score: 100
Accepted
time: 12ms
memory: 10624kb

input:

1
4
8 -7 9 1

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 1991ms
memory: 299168kb

input:

59056
10
0 1 1 0 1 0 1 1 1 0
10
-1 -1 -1 1 0 0 1 0 0 1
10
1 0 0 1 1 1 -1 -1 0 1
10
-1 1 -1 1 0 1 1 0 -1 1
10
1 0 0 1 -1 0 -1 -1 -1 1
10
1 1 1 0 0 -1 -1 1 0 0
10
-1 1 0 0 1 -1 -1 0 -1 -1
10
1 -1 0 0 0 -1 -1 -1 -1 -1
10
0 0 0 1 1 0 0 1 -1 1
10
0 -1 0 0 1 0 1 1 1 0
10
0 0 0 0 1 -1 1 -1 -1 -1
10
-1 0 1 ...

output:

6
3
3
3
1
3
1
1
3
4
1
2
3
6
1
1
4
2
1
1
4
1
3
2
3
1
5
1
1
2
3
1
1
2
2
3
0
5
1
1
2
1
1
2
3
2
1
2
1
3
1
2
3
2
3
2
3
2
5
1
3
2
2
2
2
1
1
2
2
3
2
1
3
1
2
1
1
2
2
1
2
1
1
3
1
3
1
1
2
1
2
2
3
2
1
2
1
1
3
3
1
1
2
1
1
3
1
2
2
1
1
1
3
3
2
1
3
2
3
2
2
4
2
1
2
4
3
5
2
2
4
1
1
2
1
1
2
2
5
3
3
0
2
2
2
1
1
2
1
2
...

result:

ok 59056 numbers