using
System;
using
System.Collections.Generic;
using
System.Linq;
public
class
Train {
public
string
train_num;
public
int
arrival_time;
public
int
stoppage_time;
public
Train(
string
train_num,
int
arrival_time,
int
stoppage_time) {
this
.train_num = train_num;
this
.arrival_time = arrival_time;
this
.stoppage_time = stoppage_time;
}
}
public
class
PlatformComparator : IComparer<
int
[]> {
public
int
Compare(
int
[] platform1,
int
[] platform2) {
if
(platform1[1] == platform2[1]) {
return
platform1[0].CompareTo(platform2[0]);
}
return
platform1[1].CompareTo(platform2[1]);
}
}
public
class
Program {
public
static
int
FindPlatformOf(List<Train> trains,
int
n,
string
F) {
trains.Sort((x, y) => x.arrival_time.CompareTo(y.arrival_time));
var
pq =
new
SortedSet<
int
[]>(
new
PlatformComparator());
var
temp =
new
int
[] { 1, 0 };
pq.Add(temp);
var
schedule =
new
Dictionary<
string
,
int
>();
foreach
(
var
t
in
trains) {
var
free_platform = pq.Min;
pq.Remove(free_platform);
if
(t.arrival_time >= free_platform[1]) {
free_platform[1] = t.arrival_time + t.stoppage_time + 1;
pq.Add(free_platform);
schedule[t.train_num] = free_platform[0];
}
else
{
pq.Add(free_platform);
int
platform_num = pq.Count + 1;
var
new_platform =
new
int
[] { platform_num, t.arrival_time + t.stoppage_time + 1 };
pq.Add(new_platform);
schedule[t.train_num] = platform_num;
}
}
return
schedule[F];
}
public
static
void
Main() {
var
trains =
new
List<Train>() {
new
Train(
"112567"
, 2, 1),
new
Train(
"112569"
, 5, 5),
new
Train(
"112563"
, 5, 3),
new
Train(
"112560"
, 3, 7),
};
string
F =
"112563"
;
Console.WriteLine(FindPlatformOf(trains, trains.Count, F));
}
}