Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <vector>
  5. #include <set>
  6. #include <map>
  7. #include <algorithm>
  8.  
  9. using namespace std;
  10.  
  11. typedef long long LL;
  12. typedef pair<int, int> pii;
  13. typedef pair<LL, LL> pll;
  14. typedef pair<string, string> pss;
  15. typedef vector<int> vi;
  16. typedef vector<vi> vvi;
  17. typedef vector<pii> vii;
  18. typedef vector<LL> vl;
  19. typedef vector<vl> vvl;
  20. #pragma warning(disable:4996)
  21.  
  22.  
  23. struct t {
  24.     long long hour, m, sec;
  25. };
  26.  
  27. bool cmp(t a, t b) {
  28.     if (a.hour != b.hour)
  29.         return a.hour > b.hour;
  30.     else if (a.m != b.m)
  31.         return a.m > b.m;
  32.     else
  33.         return a.sec > b.sec;
  34. }
  35.  
  36. int main() {
  37.     int n;
  38.     cin >> n;
  39.     vector <long long> arr(n);
  40.  
  41.     for (int i = 0; i < n; i++) {
  42.         long long x, y, z;
  43.         scanf("%lld:%lld:%lld", &x, &y, &z);
  44.         if (x == 12)
  45.             arr[i] = y * 60 + z;
  46.         else
  47.             arr[i] = x * 3600 + y * 60 + z;
  48.     }
  49.     sort(arr.begin(), arr.end());
  50.     vector <int> dp(n);
  51.     for (int i = 1; i < n; i++) {
  52.         dp[0] += 43200 - arr[i] + arr[0];
  53.     }
  54.  
  55.     long long ans = arr[0];
  56.     long long min = dp[0];
  57.     for (int i = 1; i < n; i++) {
  58.         dp[i] = dp[i - 1] - (43199 - arr[i] + arr[i - 1]) + (arr[i] - arr[i - 1]) * (n - 1);
  59.         if (dp[i] < min)
  60.             ans = arr[i], min = dp[i];
  61.     }
  62.  
  63.     long long ans_hour, ans_min, ans_sec;
  64.     ans_sec = ans % 3600 % 60;
  65.     ans_hour = ans / 3600;
  66.  
  67.     if (ans_hour == 0)
  68.         ans_hour = 12;
  69.     ans_min = ans % 3600 / 60;
  70.     printf("%lld:%02lld:%02lld", ans_hour, ans_min, ans_sec);
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement