Wettbewerbsfähige ProgrammierungEinfach

Jobsequenzierung

Detaillierte Anleitung und Python-Implementierung für das Problem „Job Sequencing“.

Problemstellung

Einfach

Schreiben Sie eine Funktion job_scheduling(jobs), die eine Liste von Tupeln jobs akzeptiert, wobei jedes Tupel (job_id, deadline, profit) ist. Für jeden Job wird 1 Zeiteinheit benötigt. Ermitteln Sie den maximalen Gewinn und die Anzahl der abgeschlossenen Jobs und geben Sie diese als Tupel (job_count, max_profit) zurück.

Einschränkungen
  • 1 <= len(jobs) <= 10^4
  • 1 <= deadline <= 100
  • 1 <= profit <= 1000

Beispiele

Example 1
Input
job_scheduling([(1, 4, 20), (2, 1, 10), (3, 1, 40), (4, 1, 30)])
Output
(2, 60)
Explanation

We can do job 3 at time 1 and job 1 at time 2. Total profit is 40 + 20 = 60.

Example 2
Input
job_scheduling([(1, 2, 100), (2, 1, 19), (3, 2, 27), (4, 1, 25), (5, 3, 15)])
Output
(3, 142)
Explanation

We can do job 1, 3, and 5 for a total profit of 100 + 27 + 15 = 142.

Need a Hint?
Erwägen Sie die Verwendung von Greedy-spezifischen Datenstrukturen wie Sets oder Heaps.
Edge Cases to Watch
  • Leere Eingabestrukturen
  • Einzelelementeingaben
  • Große numerische Grenzen

Bereit zur Lösung?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Im Editor öffnen
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Empfohlene Python-Ressourcen

Erweitern Sie Ihr Wissen mit zugehörigen interaktiven Tutorials, Spickzetteln und Codevergleichen.