Submission #58459037
Source Code Expand
Copy
def solve(N, K):total_sum = sum(K)possible_sums = {0}for k in K:new_sums = set()for s in possible_sums:new_sums.add(s + k)possible_sums.update(new_sums)half_sum = total_sum // 2best_s = max(s for s in possible_sums if s <= half_sum)return max(best_s, total_sum - best_s)N = int(input())K = list(map(int, input().split()))print(solve(N, K))
def solve(N, K): total_sum = sum(K) possible_sums = {0} for k in K: new_sums = set() for s in possible_sums: new_sums.add(s + k) possible_sums.update(new_sums) half_sum = total_sum // 2 best_s = max(s for s in possible_sums if s <= half_sum) return max(best_s, total_sum - best_s) N = int(input()) K = list(map(int, input().split())) print(solve(N, K))
Submission Info
Submission Time | |
---|---|
Task | C - Separated Lunch |
User | meriam |
Language | Python (PyPy 3.10-v7.3.12) |
Score | 300 |
Code Size | 441 Byte |
Status | AC |
Exec Time | 295 ms |
Memory | 296680 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example_00.txt, example_01.txt, example_02.txt |
All | example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
example_00.txt | AC | 55 ms | 76696 KB |
example_01.txt | AC | 56 ms | 76348 KB |
example_02.txt | AC | 55 ms | 76652 KB |
hand_00.txt | AC | 56 ms | 76264 KB |
hand_01.txt | AC | 56 ms | 76480 KB |
hand_02.txt | AC | 212 ms | 296316 KB |
hand_03.txt | AC | 55 ms | 76244 KB |
hand_04.txt | AC | 56 ms | 76828 KB |
hand_05.txt | AC | 270 ms | 296292 KB |
random_00.txt | AC | 109 ms | 155936 KB |
random_01.txt | AC | 115 ms | 156228 KB |
random_02.txt | AC | 169 ms | 238616 KB |
random_03.txt | AC | 170 ms | 238292 KB |
random_04.txt | AC | 283 ms | 296680 KB |
random_05.txt | AC | 170 ms | 237916 KB |
random_06.txt | AC | 115 ms | 157124 KB |
random_07.txt | AC | 173 ms | 238200 KB |
random_08.txt | AC | 285 ms | 296192 KB |
random_09.txt | AC | 108 ms | 156240 KB |
random_10.txt | AC | 112 ms | 156348 KB |
random_11.txt | AC | 170 ms | 238628 KB |
random_12.txt | AC | 167 ms | 238620 KB |
random_13.txt | AC | 288 ms | 296296 KB |
random_14.txt | AC | 295 ms | 296400 KB |
random_15.txt | AC | 256 ms | 293400 KB |
random_16.txt | AC | 158 ms | 232844 KB |
random_17.txt | AC | 108 ms | 146912 KB |
random_18.txt | AC | 208 ms | 293920 KB |
random_19.txt | AC | 152 ms | 211876 KB |
random_20.txt | AC | 256 ms | 292452 KB |