fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n, A, B, tn, retA, retB;
  4. string st, pre;
  5.  
  6. string print(int a){
  7. string min = "00" + to_string(a / 60);
  8. string sec = "00" + to_string(a % 60);
  9. return min.substr(min.size() - 2, 2) + ":" + sec.substr(sec.size() - 2, 2);
  10. }
  11.  
  12. int changeToInt(string s){
  13. return atoi(s.substr(0, 2).c_str()) * 60 + atoi(s.substr(3, 2).c_str());
  14. }
  15.  
  16. void go(int &sum, string s){
  17. sum += changeToInt(s) - changeToInt(pre);
  18. }
  19. int main(){
  20. cin >> n;
  21. pre = "kundol";
  22. for(int i = 0; i < n; i++){
  23. cin >> tn >> st;
  24. if(tn == 1) A++;
  25. else B++;
  26.  
  27. if(A > B) go(retA, st);
  28. else if(B > A) go(retB, st);
  29. pre = st;
  30. }
  31. if(A > B) go(retA, "48:00");
  32. else if(B > A) go(retB, "48:00");
  33.  
  34. cout << print(retA) << '\n';
  35. cout << print(retB) << '\n';
  36. }
Success #stdin #stdout 0.01s 5288KB
stdin
3
1 01:10
2 21:10
2 31:30
stdout
01:10
26:50