QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#743456#3138. Length of Bundle Ropevwxyz#AC ✓21ms12356kbPython31.0kb2024-11-13 19:15:542024-11-13 19:15:59

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 19:15:59]
  • 评测
  • 测评结果:AC
  • 用时:21ms
  • 内存:12356kb
  • [2024-11-13 19:15:54]
  • 提交

answer

import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
import time
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines
write=sys.stdout.write
#import pypyjit
#pypyjit.set_param('max_unroll_recursion=-1')
#sys.set_int_max_str_digits(10**9)

T=int(input())
for t in range(T):
    N=int(input())
    A=list(map(int,input().split()))
    heapify(A)
    ans=0
    for _ in range(N-1):
        a=heappop(A)
        b=heappop(A)
        heappush(A,a+b)
        ans+=a+b
    print(ans)

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 20ms
memory: 12292kb

input:

4
6
2 3 4 4 5 7
5
5 15 40 30 10
10
3 1 5 4 8 2 6 1 1 2
9
3 2 1 6 5 2 6 4 3

output:

63
205
100
98

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 21ms
memory: 12356kb

input:

10
317
433 571 952 914 928 387 359 997 381 987 801 614 17 897 225 24 451 874 281 615 417 629 61 258 339 935 907 112 706 880 646 879 257 502 795 739 715 440 843 373 757 974 866 284 437 624 575 680 732 604 669 740 352 324 818 603 893 127 310 143 364 238 534 926 572 273 858 814 393 348 91 2 554 293 465...

output:

1249288
2229139
2550728
444394
243473
1034499
2418139
4488000
4862448
9976

result:

ok 10 lines