- list_weights 를 memory 가 300MiB ~ 600MiB 인 어플리케이션으로 채워둠 (이 안에 있는 어필리케이션은 1개 혹은 2개가 짝을 지어서 하나의 서버에 들어갈수 있음)
- list_weights 를 sorting 하고 큰 것부터 차례대로 서버에 할당하면서 같이 서버에 넣을수있는 어필리케이션 중 가장 큰 메모리를 가지고 있는 어플리케이션을 서버에 같이 넣음
이렇게 풀면 subtask 3,4 에서 일부 오답이 나오네요.. 혹시 도움 주실수 있는 분이 계실까요?
import bisect
from collections
import Counter
T =
int(sys.stdin.readline().rstrip())
def
update(
counter,
sorted_list,
val):
counter.subtract(Counter({val:
1}))
if counter[val] ==
0:
del counter[val]
if val
not
in counter:
sorted_list.remove(val)
for _
in
range(T):
_ =
int(sys.stdin.readline().rstrip())
list_weights = []
count =
0
n_300 =
0
for el
in [
int(el)
for el
in sys.stdin.readline().split()]:
if el ==
300:
n_300 +=
1
elif el >
600:
count +=
1
else:
list_weights.append(
int(el))
count += n_300//
3
list_weights += [
300]*(n_300 %
3)
counter = Counter(list_weights)
unique_weight_sorted =
sorted(
set(counter.elements()))
while
len(unique_weight_sorted)!=
0:
count+=
1
curr_w = unique_weight_sorted[-
1]
update(counter, unique_weight_sorted, curr_w)
cand_recip_w =
900 - curr_w
index_recip = bisect.bisect_right(unique_weight_sorted, cand_recip_w) -
1
if index_recip >=
0:
recip_w = unique_weight_sorted[index_recip]
update(counter, unique_weight_sorted, recip_w)
print(count)