Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <string>
- using namespace std;
- int getn(string s) {
- int n = 0;
- string ans = "";
- for (int i = 0; i < s.size(); i++)
- if (isdigit(s[i]))
- ans.push_back(s[i]);
- else {
- if (n == 0)
- n += (stoi(ans) - 1) * 3600;
- else
- n += stoi(ans) * 60;
- ans = "";
- }
- n += stoi(ans);
- return n;
- }
- int main() {
- int n;
- cin >> n;
- vector <int> a(n);
- for (int i = 0; i < n; i++) {
- string s;
- cin >> s;
- a[i] = getn(s);
- }
- sort(a.begin(), a.end());
- vector <int> dp(43200, 0);
- int ind = 0;
- while (a[ind] == 0)
- ind++;
- for (int i = 0; i < n; i++) {
- if (a[i] != 0)
- dp[0] += 43200 - a[i];
- }
- //int r = dp[0];
- for (int i = 1; i < 43200; i++) {
- int r = dp[i - 1];
- int count = ind;
- while (ind < n && a[ind] == i)
- ind++;
- int d = dp[i - 1] + n - (ind - count) - 43200 * (ind - count);
- dp[i] = d;
- }
- int ans = 1e9;
- int t = 0;
- for (int i = 0; i < 43200; i++)
- if (dp[i] < ans) {
- ans = dp[i];
- t = i;
- }
- int h = t / 3600;
- int m = (t - h * 3600) / 60;
- int s = (t - h * 3600 - m * 60);
- string ss = "";
- h++;
- ss += to_string(h);
- ss += ":";
- if (m < 10) {
- ss += "0";
- ss += to_string(m);
- }
- else ss += to_string(m);
- ss += ":";
- if (s < 10) {
- ss += "0";
- ss += to_string(s);
- }
- else ss += to_string(s);
- cout << ss;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement