fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int convert(string s){
  6. int u1 = (s[0]-'0')*10 + (s[1]-'0'); // hours
  7. int u2 = (s[3]-'0')*10 + (s[4]-'0'); // minutes
  8. return u1*60 + u2;
  9. }
  10.  
  11.  
  12.  
  13. void ck(int g){
  14. int u = g/60;
  15. int y = g%60;
  16.  
  17. if(u<=9){
  18. cout<<"0";
  19. cout<<u;
  20. }
  21. else{
  22. cout<<u;
  23. }
  24. cout<<":";
  25.  
  26.  
  27. if(y<=9){
  28. cout<<"0";
  29. cout<<y;
  30. }
  31. else{
  32. cout<<y;
  33. }
  34. }
  35.  
  36. int main() {
  37. int n;
  38. cin>>n;
  39.  
  40. int k ;
  41. cin>>k;
  42.  
  43. int y[1441] = {0};
  44.  
  45. for(int i=0;i<n;i++){
  46. string a,b,v1,v5;
  47. cin>>a;
  48. cin>>b;
  49. cin>>v1>>v5;
  50.  
  51. int t1 = convert(v1);
  52. int t5 = convert(v5);
  53. //cout<<t1<<" "<<t5;
  54. //cout<<'\n';
  55. y[t1] = y[t1] + 1 ;
  56. y[t5+1] = y[t5+1] - 1 ;
  57. }
  58.  
  59.  
  60. int i=1;
  61. while(i<1440){
  62.  
  63. y[i] = y[i] + y[i-1];
  64.  
  65. i++;
  66. }
  67. int x=0;
  68. int c = 0 ; int g = 0 ;
  69.  
  70. for (int i=0; i<1440; i++) {
  71. if (y[i] > 0) x = 1; // after first busy, x=1
  72. if (y[i] == 0) {
  73. if (x == 1) {
  74. c++;
  75. if (c == k) { ck(i-k+1); g=1; break; }
  76. }
  77. } else c=0;
  78. }
  79.  
  80.  
  81. if(g==0){
  82. cout<<"-1";
  83. }
  84.  
  85.  
  86.  
  87. }
Success #stdin #stdout 0.01s 5292KB
stdin
1 2 a b
00:00 23:59
stdout
-1