Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- #include <stdio.h>
- #include <vector>
- #include <set>
- #include <map>
- #include <algorithm>
- using namespace std;
- typedef long long LL;
- typedef pair<int, int> pii;
- typedef pair<LL, LL> pll;
- typedef pair<string, string> pss;
- typedef vector<int> vi;
- typedef vector<vi> vvi;
- typedef vector<pii> vii;
- typedef vector<LL> vl;
- typedef vector<vl> vvl;
- #pragma warning(disable:4996)
- struct t {
- long long hour, m, sec;
- };
- bool cmp(t a, t b) {
- if (a.hour != b.hour)
- return a.hour > b.hour;
- else if (a.m != b.m)
- return a.m > b.m;
- else
- return a.sec > b.sec;
- }
- int main() {
- int n;
- cin >> n;
- vector <long long> arr(n);
- for (int i = 0; i < n; i++) {
- long long x, y, z;
- scanf("%lld:%lld:%lld", &x, &y, &z);
- if (x == 12)
- arr[i] = y * 60 + z;
- else
- arr[i] = x * 3600 + y * 60 + z;
- }
- sort(arr.begin(), arr.end());
- vector <int> dp(n);
- for (int i = 1; i < n; i++) {
- dp[0] += 43200 - arr[i] + arr[0];
- }
- long long ans = arr[0];
- long long min = dp[0];
- for (int i = 1; i < n; i++) {
- dp[i] = dp[i - 1] - (43199 - arr[i] + arr[i - 1]) + (arr[i] - arr[i - 1]) * (n - 1);
- if (dp[i] < min)
- ans = arr[i], min = dp[i];
- }
- long long ans_hour, ans_min, ans_sec;
- ans_sec = ans % 3600 % 60;
- ans_hour = ans / 3600;
- if (ans_hour == 0)
- ans_hour = 12;
- ans_min = ans % 3600 / 60;
- printf("%lld:%02lld:%02lld", ans_hour, ans_min, ans_sec);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement