Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. int n;
  10. freopen("input.txt", "r", stdin);
  11. scanf("%d", &n);
  12. vector<int> a(n);
  13. for (int i = 0; i < n; ++i) {
  14. int h, m, s;
  15. scanf("%d:%d:%d", &h, &m, &s);
  16. a[i] = h * 3600 + m * 60 + s - 3600;
  17. }
  18. sort(a.begin(), a.end());
  19. long long sum = 0, mi, time;
  20. for (int i = 0;i < n - 1; ++i) {
  21. sum += a.back() - a[i];
  22. }
  23. mi = sum;
  24. time = a.back();
  25. int last = 1;
  26. for (int i = n - 2; i >= 0; --i) {
  27. sum -= (i + 1) * (a[i + 1] - a[i]);
  28. if (a[i] != a[i + 1]) {
  29. sum -= (n - i - 2) * (a[i + 1] - a[i]) * last;
  30. sum += (3600 * 12 - a[i + 1] + a[i]) * last;
  31. last = 1;
  32. } else {
  33. last++;
  34. }
  35. if (mi > sum) {
  36. mi = sum;
  37. time = a[i];
  38. }
  39. }
  40. time += 3600;
  41. printf("%d:", time / 3600);
  42. time %= 3600;
  43. printf("%02d:", time / 60);
  44. time %= 60;
  45. printf("%02d", time);
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement