結果

問題 No.999 てん vs. ほむ
ユーザー Raymin012Raymin012
提出日時 2020-02-28 23:20:12
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 847 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 30,660 KB
最終ジャッジ日時 2024-10-13 19:12:04
合計ジャッジ時間 4,324 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 WA * 7 TLE * 2 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int,input().split()))
hom = 0
tmp = 0
for i in range(n):
    if len(a) == 2:
        if a[0] >= a[1]:
            hom += a[0]
            tmp += a[1]
            break
            
        else:
            hom += a[1]
            tmp += a[0]
            break
    else:
        if a[0] >= a[1]:
            hom += a.pop(0)
            tmp += a.pop(0)
            if len(a) == 0:
                break
        if a[-1] >= a[-2]:
            hom += a.pop()
            tmp += a.pop()
            if len(a) == 0:
                break
        if a[1] > a[0] and a[-2] > a[-1] and len(a) > 2:
            if abs(a[1] - a[0]) >= abs(a[-2] - a[-1]):
                hom += a.pop()
                tmp += a.pop()
            else:
                hom += a.pop(0)
                tmp += a.pop(0)
print(hom-tmp)

            
0