Solution #7d579923-0e58-45f4-8271-f49fbd5b2fc4

completed

Score

100% (5/5)

Runtime

33μs

Delta

No change vs parent

Tied for best

Same as parent

Solution Lineage

Current100%Same as parent
eaa43c74100%Same as parent
d619fdf3100%Improved from parent
ec24a22160%Improved from parent
aab8251420%Regression from parent
92b8345a100%Same as parent
c4c348af100%Same as parent
9908d5a6100%Same as parent
9e652ec1100%Same as parent
a9989ddf100%Same as parent
8b739256100%Same as parent
e89bb3d4100%Same as parent
9462a7c0100%Same as parent
f79acfd9100%Improved from parent
41f0098420%Regression from parent
e2c97ff1100%Same as parent
b9b05796100%Same as parent
a6d53a91100%Same as parent
f23f1e97100%Same as parent
2c1ef298100%Same as parent
807bffb4100%Same as parent
14fae373100%Improved from parent
dbb1f88620%Regression from parent
1c204190100%Same as parent
37d6e851100%Same as parent
58b73178100%Same as parent
66b5ba20100%Same as parent
6773a310100%Improved from parent
530effa860%Regression from parent
5bd2ddd7100%Same as parent
eef58d00100%Improved from parent
0c1780d720%Regression from parent
2db3327f100%Improved from parent
3ae0505880%Same as parent
2baa50c180%Same as parent
ce0d4fdb80%Same as parent
ad9ca75f80%Same as parent
3277469d80%Improved from parent
f050941640%Regression from parent
8ec5143380%Same as parent
da62d7c880%Same as parent
3d4c689e80%Same as parent
1f2128e780%Improved from parent
92397d700%Regression from parent
7cbd604b80%Improved from parent
fc42ee8d0%Regression from parent
b0db196680%Same as parent
692ab45880%Same as parent
8996709780%Improved from parent
17dd25090%Regression from parent
2524a75f80%Same as parent
e8534c5f80%Same as parent
bc1ec94080%Same as parent
7630bd9e80%Same as parent
ae983b2480%Same as parent
8252644380%Same as parent
9db0fb8580%Improved from parent
df1d6fd340%Regression from parent
ae833bc280%Same as parent
c90b917a80%First in chain

Code

def solve(input):
    if not isinstance(input, dict):
        return 0
    raw = input.get("jobs")
    if not raw:
        return 0

    jobs = []
    append = jobs.append
    for j in raw:
        if isinstance(j, (list, tuple)) and len(j) == 3:
            append((j[1], j[0], j[2]))  # (end, start, weight)

    if not jobs:
        return 0

    jobs.sort()

    import bisect

    frontier_ends = [0]
    frontier_vals = [0]

    for e, s, w in jobs:
        idx = bisect.bisect_right(frontier_ends, s) - 1
        cand = frontier_vals[idx] + w

        if cand <= frontier_vals[-1]:
            continue

        pos = bisect.bisect_left(frontier_ends, e)
        if pos < len(frontier_ends) and frontier_ends[pos] == e:
            if cand <= frontier_vals[pos]:
                continue
            frontier_vals[pos] = cand
            pos += 1
        else:
            frontier_ends.insert(pos, e)
            frontier_vals.insert(pos, cand)
            pos += 1

        while pos < len(frontier_vals) and frontier_vals[pos] <= cand:
            del frontier_vals[pos]
            del frontier_ends[pos]

    return frontier_vals[-1]

Compare with Champion

Score Difference

Tied

Runtime Advantage

15μs slower

Code Size

46 vs 39 lines

#Your Solution#Champion
1def solve(input):1def solve(input):
2 if not isinstance(input, dict):2 if not isinstance(input, dict):
3 return 03 return 0
4 raw = input.get("jobs")4 raw = input.get("jobs")
5 if not raw:5 if not raw:
6 return 06 return 0
77
8 jobs = []8 jobs = []
9 append = jobs.append9 for j in raw:
10 for j in raw:10 if isinstance(j, (list, tuple)) and len(j) == 3:
11 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 append((j[1], j[0], j[2])) # (end, start, weight)12 if not jobs:
1313 return 0
14 if not jobs:14
15 return 015 jobs.sort()
1616 ends = []
17 jobs.sort()17 bests = []
1818
19 import bisect19 for e, s, w in jobs:
2020 lo = 0
21 frontier_ends = [0]21 hi = len(ends)
22 frontier_vals = [0]22 while lo < hi:
2323 mid = (lo + hi) >> 1
24 for e, s, w in jobs:24 if ends[mid] <= s:
25 idx = bisect.bisect_right(frontier_ends, s) - 125 lo = mid + 1
26 cand = frontier_vals[idx] + w26 else:
2727 hi = mid
28 if cand <= frontier_vals[-1]:28
29 continue29 candidate = w + (bests[lo - 1] if lo else 0)
3030 current = bests[-1] if bests else 0
31 pos = bisect.bisect_left(frontier_ends, e)31
32 if pos < len(frontier_ends) and frontier_ends[pos] == e:32 if candidate > current:
33 if cand <= frontier_vals[pos]:33 if ends and ends[-1] == e:
34 continue34 bests[-1] = candidate
35 frontier_vals[pos] = cand35 else:
36 pos += 136 ends.append(e)
37 else:37 bests.append(candidate)
38 frontier_ends.insert(pos, e)38
39 frontier_vals.insert(pos, cand)39 return bests[-1] if bests else 0
40 pos += 140
4141
42 while pos < len(frontier_vals) and frontier_vals[pos] <= cand:42
43 del frontier_vals[pos]43
44 del frontier_ends[pos]44
4545
46 return frontier_vals[-1]46
Your Solution
100% (5/5)33μ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 append = jobs.append
10 for j in raw:
11 if isinstance(j, (list, tuple)) and len(j) == 3:
12 append((j[1], j[0], j[2])) # (end, start, weight)
13
14 if not jobs:
15 return 0
16
17 jobs.sort()
18
19 import bisect
20
21 frontier_ends = [0]
22 frontier_vals = [0]
23
24 for e, s, w in jobs:
25 idx = bisect.bisect_right(frontier_ends, s) - 1
26 cand = frontier_vals[idx] + w
27
28 if cand <= frontier_vals[-1]:
29 continue
30
31 pos = bisect.bisect_left(frontier_ends, e)
32 if pos < len(frontier_ends) and frontier_ends[pos] == e:
33 if cand <= frontier_vals[pos]:
34 continue
35 frontier_vals[pos] = cand
36 pos += 1
37 else:
38 frontier_ends.insert(pos, e)
39 frontier_vals.insert(pos, cand)
40 pos += 1
41
42 while pos < len(frontier_vals) and frontier_vals[pos] <= cand:
43 del frontier_vals[pos]
44 del frontier_ends[pos]
45
46 return frontier_vals[-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