fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void executeTime() {
  5. cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " secs";
  6. }
  7.  
  8. int main() {
  9.  
  10. int n, k; cin >> n >> k;
  11.  
  12. cin.ignore();
  13.  
  14. vector<string> events(n);
  15. for (int i = 0; i < n; i++) {
  16. getline(cin, events[i], '\n');
  17. }
  18.  
  19. vector<int> time(1440, 0);
  20.  
  21. for (int i = 0; i < n; i++) {
  22. stringstream ss(events[i]);
  23.  
  24. vector<string> v;
  25.  
  26. string word;
  27. while (ss >> word) {
  28. v.push_back(word);
  29. }
  30.  
  31. string h = v[2].substr(0, 2);
  32. string m = v[2].substr(3, 2);
  33. int st = stoi(h) * 60 + stoi(m);
  34. time[st]++;
  35.  
  36. h = v[3].substr(0, 2);
  37. m = v[3].substr(3, 2);
  38. int en = stoi(h) * 60 + stoi(m);
  39. time[en + 1] -= 1;
  40. }
  41.  
  42.  
  43.  
  44. for (int i = 1; i < 1440; i++) {
  45. time[i] += time[i - 1];
  46. }
  47.  
  48. int i = 0, ans = -1, cnt = 0;
  49.  
  50. for (int i = 0; i < 1440; i++) {
  51. if (time[i] == 0) {
  52. cnt++;
  53.  
  54. if (cnt == k) {
  55. ans = i - cnt + 1;
  56. break;
  57. }
  58.  
  59.  
  60. } else {
  61. cnt = 0;
  62. }
  63. }
  64.  
  65. cout << ans << endl;
  66.  
  67.  
  68. executeTime();
  69. return 0;
  70. }
Success #stdin #stdout #stderr 0s 5324KB
stdin
3 60
Alex sleep 00:00 08:00 
Sam sleep 07:00 13:00
Alex lunch 12:30 13:59
stdout
840
stderr
Time Taken: 0.004289 secs