728x90
728x90
#include <string>
#include <vector>
#include <sstream>
#include <queue>
using namespace std;
vector<int> dp(360000,0);
string solution(string play_time, string adv_time, vector<string> logs) {
string answer = "";
int start_hh,start_mm,start_ss , end_hh,end_mm,end_ss,start_time,end_time;
int total_time,ad_time,idx = 0;
char extra;
stringstream ss(play_time),st(adv_time);
ss >> start_hh >> extra >> start_mm >> extra >> start_ss;
total_time = (start_hh * 3600) + (start_mm * 60) + start_ss;
st >> end_hh >> extra >> end_mm >> extra >> end_ss;
ad_time = (end_hh * 3600) + (end_mm * 60) + end_ss;
for(auto s : logs)
{
stringstream t(s);
t >> start_hh >> extra >> start_mm >> extra >> start_ss >> extra >> end_hh >> extra >> end_mm >> extra >> end_ss;
start_time = (start_hh * 3600) + (start_mm * 60) + start_ss;
end_time = (end_hh * 3600) + (end_mm * 60) + end_ss;
for(int i=start_time ;i < end_time; i++) dp[i]++;
}
long long sum = 0, max_sum = 0;
queue<int> q;
for(int i=0; i<ad_time ; i++) sum += dp[i] ,q.push(dp[i]);
max_sum = sum;
for(int i=ad_time; i<total_time; i++)
{
sum += dp[i];
q.push(dp[i]);
sum -= q.front();
q.pop();
if(sum > max_sum)
{
idx = i - ad_time + 1;
max_sum = sum;
}
}
int ho = idx / 3600 ;
int mo = idx % 3600 / 60;
int se = idx % 3600 % 60;
if(ho < 10)
{
answer += "0" + to_string(ho) + ":";
if(mo < 10)
{
answer += "0" +to_string(mo) + ":";
if(se <10 ) answer += "0" +to_string(se);
else answer += to_string(se);
}
else
{
answer += to_string(mo) + ":";
if(se <10 ) answer += "0" +to_string(se);
else answer += to_string(se);
}
}
else
{
answer += to_string(ho) + ":";
if(mo < 10)
{
answer += "0" +to_string(mo) + ":";
if(se <10 ) answer += "0" +to_string(se);
else answer += to_string(se);
}
else
{
answer += to_string(mo) + ":";
if(se <10 ) answer += "0" +to_string(se);
else answer += to_string(se);
}
}
return answer;
}
728x90
728x90