Solved LeetCode program · 793 of 1,000
#1029 · Two City Scheduling
Original English source
The firsts is a list of 10, 30, 400, and 30. The seconds is a list of 20, 200, 50, and 20. The size is 4. The wanted is 2. The order is an empty list of whole numbers. The gaps is an empty list of whole numbers.
For every city from 0 to 3.
Place city into order. Place item city of firsts minus item city of seconds into gaps.
For every spot from 0 to 3.
For every look from spot plus 1 to 3.
The here is item spot of order. The there is item look of order. If item there of gaps is less than item here of gaps, swap item spot of order and item look of order.
The total is 0.
For every city from 0 to 3.
The picked is item city of order. If city is less than wanted, set total to total plus item picked of firsts. If city is at least wanted, set total to total plus item picked of seconds.
Show total.
Expected stdout
110