Solution #82526443-92a4-468f-983c-3d3ffbe48d15

completed

Score

80% (4/5)

Runtime

15μs

Delta

No change vs parent

-20.0% vs best

Same as parent

Solution Lineage

Current80%Same as parent
9db0fb8580%Improved from parent
df1d6fd340%Regression from parent
ae833bc280%Same as parent
c90b917a80%First in chain

Code

def solve(input):
    jobs = input.get("jobs", [])
    if not jobs:
        return 0

    jobs = sorted(jobs, key=lambda x: x[1])

    best_end = [0]
    best_val = [0]

    for s, e, w in jobs:
        lo, hi = 0, len(best_end) - 1
        idx = 0
        while lo <= hi:
            mid = (lo + hi) // 2
            if best_end[mid] <= s:
                idx = mid
                lo = mid + 1
            else:
                hi = mid - 1

        cand = best_val[idx] + w
        if cand > best_val[-1]:
            if best_end[-1] == e:
                best_val[-1] = cand
            else:
                best_end.append(e)
                best_val.append(cand)

    return best_val[-1]

Compare with Champion

Score Difference

-20.0%

Runtime Advantage

3μs faster

Code Size

30 vs 39 lines

#Your Solution#Champion
1def solve(input):1def solve(input):
2 jobs = input.get("jobs", [])2 if not isinstance(input, dict):
3 if not jobs:3 return 0
4 return 04 raw = input.get("jobs")
55 if not raw:
6 jobs = sorted(jobs, key=lambda x: x[1])6 return 0
77
8 best_end = [0]8 jobs = []
9 best_val = [0]9 for j in raw:
1010 if isinstance(j, (list, tuple)) and len(j) == 3:
11 for s, e, w in jobs:11 jobs.append((j[1], j[0], j[2])) # sort by end, store as (end, start, weight)
12 lo, hi = 0, len(best_end) - 112 if not jobs:
13 idx = 013 return 0
14 while lo <= hi:14
15 mid = (lo + hi) // 215 jobs.sort()
16 if best_end[mid] <= s:16 ends = []
17 idx = mid17 bests = []
18 lo = mid + 118
19 else:19 for e, s, w in jobs:
20 hi = mid - 120 lo = 0
2121 hi = len(ends)
22 cand = best_val[idx] + w22 while lo < hi:
23 if cand > best_val[-1]:23 mid = (lo + hi) >> 1
24 if best_end[-1] == e:24 if ends[mid] <= s:
25 best_val[-1] = cand25 lo = mid + 1
26 else:26 else:
27 best_end.append(e)27 hi = mid
28 best_val.append(cand)28
2929 candidate = w + (bests[lo - 1] if lo else 0)
30 return best_val[-1]30 current = bests[-1] if bests else 0
3131
3232 if candidate > current:
3333 if ends and ends[-1] == e:
3434 bests[-1] = candidate
3535 else:
3636 ends.append(e)
3737 bests.append(candidate)
3838
3939 return bests[-1] if bests else 0
Your Solution
80% (4/5)15μs
1def solve(input):
2 jobs = input.get("jobs", [])
3 if not jobs:
4 return 0
5
6 jobs = sorted(jobs, key=lambda x: x[1])
7
8 best_end = [0]
9 best_val = [0]
10
11 for s, e, w in jobs:
12 lo, hi = 0, len(best_end) - 1
13 idx = 0
14 while lo <= hi:
15 mid = (lo + hi) // 2
16 if best_end[mid] <= s:
17 idx = mid
18 lo = mid + 1
19 else:
20 hi = mid - 1
21
22 cand = best_val[idx] + w
23 if cand > best_val[-1]:
24 if best_end[-1] == e:
25 best_val[-1] = cand
26 else:
27 best_end.append(e)
28 best_val.append(cand)
29
30 return best_val[-1]
Champion
100% (5/5)18μs
1def solve(input):
2 if not isinstance(input, dict):
3 return 0
4 raw = input.get("jobs")
5 if not raw:
6 return 0
7
8 jobs = []
9 for j in raw:
10 if isinstance(j, (list, tuple)) and len(j) == 3:
11 jobs.append((j[1], j[0], j[2])) # sort by end, store as (end, start, weight)
12 if not jobs:
13 return 0
14
15 jobs.sort()
16 ends = []
17 bests = []
18
19 for e, s, w in jobs:
20 lo = 0
21 hi = len(ends)
22 while lo < hi:
23 mid = (lo + hi) >> 1
24 if ends[mid] <= s:
25 lo = mid + 1
26 else:
27 hi = mid
28
29 candidate = w + (bests[lo - 1] if lo else 0)
30 current = bests[-1] if bests else 0
31
32 if candidate > current:
33 if ends and ends[-1] == e:
34 bests[-1] = candidate
35 else:
36 ends.append(e)
37 bests.append(candidate)
38
39 return bests[-1] if bests else 0