Solution #1c204190-5e02-4844-86af-13b0273d4bc6
completedScore
100% (5/5)
Runtime
35μs
Delta
No change vs parent
Tied for best
Same as parent
Score
100% (5/5)
Runtime
35μs
Delta
No change vs parent
Tied for best
Same as parent
def solve(input):
if not isinstance(input, dict):
return 0
raw = input.get("jobs")
if not raw:
return 0
jobs = [(j[0], j[1], j[2]) for j in raw if isinstance(j, (list, tuple)) and len(j) == 3]
if not jobs:
return 0
points = sorted({t for s, e, w in jobs for t in (s, e)})
m = len(points)
index = {t: i for i, t in enumerate(points)}
buckets = [[] for _ in range(m)]
for s, e, w in jobs:
buckets[index[e]].append((index[s], w))
dp = [0] * m
best = 0
for i in range(m):
if i:
best = dp[i - 1]
cur = best
for s_idx, w in buckets[i]:
val = dp[s_idx] + w
if val > cur:
cur = val
dp[i] = cur
return dp[-1] if dp else 0Score Difference
Tied
Runtime Advantage
17μs slower
Code Size
32 vs 39 lines
| # | Your Solution | # | Champion |
|---|---|---|---|
| 1 | def solve(input): | 1 | def solve(input): |
| 2 | if not isinstance(input, dict): | 2 | if not isinstance(input, dict): |
| 3 | return 0 | 3 | return 0 |
| 4 | raw = input.get("jobs") | 4 | raw = input.get("jobs") |
| 5 | if not raw: | 5 | if not raw: |
| 6 | return 0 | 6 | return 0 |
| 7 | 7 | ||
| 8 | jobs = [(j[0], j[1], j[2]) for j in raw if isinstance(j, (list, tuple)) and len(j) == 3] | 8 | jobs = [] |
| 9 | if not jobs: | 9 | for j in raw: |
| 10 | return 0 | 10 | if isinstance(j, (list, tuple)) and len(j) == 3: |
| 11 | 11 | jobs.append((j[1], j[0], j[2])) # sort by end, store as (end, start, weight) | |
| 12 | points = sorted({t for s, e, w in jobs for t in (s, e)}) | 12 | if not jobs: |
| 13 | m = len(points) | 13 | return 0 |
| 14 | index = {t: i for i, t in enumerate(points)} | 14 | |
| 15 | 15 | jobs.sort() | |
| 16 | buckets = [[] for _ in range(m)] | 16 | ends = [] |
| 17 | for s, e, w in jobs: | 17 | bests = [] |
| 18 | buckets[index[e]].append((index[s], w)) | 18 | |
| 19 | 19 | for e, s, w in jobs: | |
| 20 | dp = [0] * m | 20 | lo = 0 |
| 21 | best = 0 | 21 | hi = len(ends) |
| 22 | for i in range(m): | 22 | while lo < hi: |
| 23 | if i: | 23 | mid = (lo + hi) >> 1 |
| 24 | best = dp[i - 1] | 24 | if ends[mid] <= s: |
| 25 | cur = best | 25 | lo = mid + 1 |
| 26 | for s_idx, w in buckets[i]: | 26 | else: |
| 27 | val = dp[s_idx] + w | 27 | hi = mid |
| 28 | if val > cur: | 28 | |
| 29 | cur = val | 29 | candidate = w + (bests[lo - 1] if lo else 0) |
| 30 | dp[i] = cur | 30 | current = bests[-1] if bests else 0 |
| 31 | 31 | ||
| 32 | return dp[-1] if dp else 0 | 32 | if candidate > current: |
| 33 | 33 | if ends and ends[-1] == e: | |
| 34 | 34 | bests[-1] = candidate | |
| 35 | 35 | else: | |
| 36 | 36 | ends.append(e) | |
| 37 | 37 | bests.append(candidate) | |
| 38 | 38 | ||
| 39 | 39 | return bests[-1] if bests else 0 |
1def solve(input):2 if not isinstance(input, dict):3 return 04 raw = input.get("jobs")5 if not raw:6 return 078 jobs = [(j[0], j[1], j[2]) for j in raw if isinstance(j, (list, tuple)) and len(j) == 3]9 if not jobs:10 return 01112 points = sorted({t for s, e, w in jobs for t in (s, e)})13 m = len(points)14 index = {t: i for i, t in enumerate(points)}1516 buckets = [[] for _ in range(m)]17 for s, e, w in jobs:18 buckets[index[e]].append((index[s], w))1920 dp = [0] * m21 best = 022 for i in range(m):23 if i:24 best = dp[i - 1]25 cur = best26 for s_idx, w in buckets[i]:27 val = dp[s_idx] + w28 if val > cur:29 cur = val30 dp[i] = cur3132 return dp[-1] if dp else 01def solve(input):2 if not isinstance(input, dict):3 return 04 raw = input.get("jobs")5 if not raw:6 return 078 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 01415 jobs.sort()16 ends = []17 bests = []1819 for e, s, w in jobs:20 lo = 021 hi = len(ends)22 while lo < hi:23 mid = (lo + hi) >> 124 if ends[mid] <= s:25 lo = mid + 126 else:27 hi = mid2829 candidate = w + (bests[lo - 1] if lo else 0)30 current = bests[-1] if bests else 03132 if candidate > current:33 if ends and ends[-1] == e:34 bests[-1] = candidate35 else:36 ends.append(e)37 bests.append(candidate)3839 return bests[-1] if bests else 0