-
Notifications
You must be signed in to change notification settings - Fork 0
/
24.cpp
59 lines (47 loc) · 977 Bytes
/
24.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//Peliculas
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
struct tPelicula {
int ini;
int fin;
};
bool menor(tPelicula a, tPelicula b) {
return a.fin < b.fin;
}
void resuelve(int nCasos) {
vector<tPelicula> peliculas = vector<tPelicula>();
tPelicula p;
string str;
int horas, minutos;
int dur;
for (int i = 0; i < nCasos; i++) {
cin >> str >> dur;
horas = stoi(str.substr(0, 2));
minutos = stoi(str.substr(3, 2));
p.ini = horas * 60 + minutos;
p.fin = p.ini + dur;
peliculas.push_back(p);
}
sort(peliculas.begin(), peliculas.end(), menor); //De menor a mayor
int ocupado = peliculas[0].fin + 10;
int nPelis = 1;
for (int i = 1; i < nCasos; i++) {
if (ocupado <= peliculas[i].ini) {
ocupado = peliculas[i].fin + 10;
nPelis++;
}
}
cout << nPelis << endl;
}
int main() {
int nCasos;
cin >> nCasos;
while (nCasos != 0) {
resuelve(nCasos);
cin >> nCasos;
}
return 0;
}