Advertisement
Guest User

WTF?

a guest
Nov 23rd, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <cstdio>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <string>
  7. #include <string.h>
  8. #include <cmath>
  9. #include <set>
  10. #include <map>
  11.  
  12.  
  13. using namespace std;
  14.  
  15.  
  16. int n, mm;
  17. int in[100000], out[100000];
  18. map<int, int> m[100000];
  19.  
  20.  
  21. int main() {
  22.     cin >> n >> mm;
  23.     for (int i = 0; i < mm; i++) {
  24.         int a, b, h = 0, m1 = 0, hh = 0, mm1 = 0;
  25.         // cin >> a;
  26.         // string s;
  27.         // cin >> s;
  28.         // bool bb = true;
  29.         // for (int j = 0; j < s.size(); j++) {
  30.         //     if (bb) {
  31.         //         if (s[j] == ':') {
  32.         //             bb = false;
  33.         //             continue;
  34.         //         }
  35.         //         h *= 10;
  36.         //         h += s[j] - '0';
  37.         //     } else {
  38.         //         m1 *= 10;
  39.         //         m1 += s[j] - '0';
  40.         //     }
  41.         //}
  42.         scanf("%d %d:%d %d %d:%d", &a, &h, &m1, &b, &hh, &mm1);
  43.         // cin >> b;
  44.         // string s1;
  45.         // cin >> s1;
  46.         // bb = true;
  47.         // for (int j = 0; j < s1.size(); j++) {
  48.         //     if (bb) {
  49.         //         if (s1[j] == ':') {
  50.         //             bb = false;
  51.         //             continue;
  52.         //         }
  53.         //         hh *= 10;
  54.         //         hh += s1[j] - '0';
  55.         //     } else {
  56.         //         mm1 *= 10;
  57.         //         mm1 += s1[j] - '0';
  58.         //     }
  59.         // }
  60.         int ss = h * 60 + m1;
  61.         int ss1 = hh * 60 + mm1;
  62.         if (ss1 < ss) {
  63.             ss1 += 24 * 60;
  64.         }
  65.         for (int j = 0; j <= 2; j++) {
  66.             m[a - 1][ss + j * 1440]--;
  67.             m[b - 1][ss1 + j * 1440]++;
  68.         }
  69.         in[b - 1]++;
  70.         out[a - 1]++;
  71.     }
  72.     for (int i = 0; i < n; i++) {
  73.         if (in[i] != out[i]) {
  74.             cout << -1 << endl;
  75.             return 0;
  76.         }
  77.     }
  78.     int ans = 0;
  79.     for (int i = 0; i < n; i++) {
  80.         int k = 0;
  81.         for (int j = 0; j <= 2880; j++) {
  82.             k += m[i][j];
  83.             if (k < 0) {
  84.                 ans += -k;
  85.                 k = 0;
  86.             }
  87.         }
  88.     }
  89.     cout << ans << endl;
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement