Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <cmath>
  5.  
  6. using vii = std::vector<std::pair<int, int> >;
  7. using vi = std::vector<int>;
  8.  
  9. int resolver(vi& g, vii const& v, int horafin, int i) {
  10. if (g[i] != -1) return g[i];
  11. if (i == v.size() - 1) {
  12. if (v[i].first >= horafin) return g[i] = 1;
  13. else return g[i] = 0;
  14. }
  15. if (v[i].first >= horafin) {
  16. int a = 1 + resolver(g, v, v[i].first + v[i].second + 10, i + 1);
  17. int b = resolver(g, v, horafin, i + 1);
  18. return g[i] = std::max(a, b);
  19. }
  20. else return g[i] = resolver(g, v, horafin, i + 1);
  21. }
  22.  
  23. bool resuelveCaso() {
  24. int n; std::cin >> n;
  25. if (n == 0) return false;
  26.  
  27. vii peliculas(n);
  28. for (int i = 0; i < n; ++i) {
  29. int h, m, t; char aux;
  30. std::cin >> h >> aux >> m >> t;
  31. peliculas[i] = std::make_pair(h * 60 + m, t);
  32. }
  33.  
  34. std::sort(peliculas.begin(), peliculas.end());
  35. vi g(n, -1);
  36.  
  37. int sol = resolver(g, peliculas, 0, 0);
  38.  
  39. std::cout << sol << std::endl;
  40.  
  41. return true;
  42. }
  43.  
  44. int main() {
  45.  
  46. while (resuelveCaso());
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement