Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <cstdio>
- #include <algorithm>
- #include <vector>
- #include <string>
- #include <string.h>
- #include <cmath>
- #include <set>
- #include <map>
- using namespace std;
- int n, mm;
- int in[100000], out[100000];
- map<int, int> m[100000];
- int main() {
- cin >> n >> mm;
- for (int i = 0; i < mm; i++) {
- int a, b, h = 0, m1 = 0, hh = 0, mm1 = 0;
- // cin >> a;
- // string s;
- // cin >> s;
- // bool bb = true;
- // for (int j = 0; j < s.size(); j++) {
- // if (bb) {
- // if (s[j] == ':') {
- // bb = false;
- // continue;
- // }
- // h *= 10;
- // h += s[j] - '0';
- // } else {
- // m1 *= 10;
- // m1 += s[j] - '0';
- // }
- //}
- scanf("%d %d:%d %d %d:%d", &a, &h, &m1, &b, &hh, &mm1);
- // cin >> b;
- // string s1;
- // cin >> s1;
- // bb = true;
- // for (int j = 0; j < s1.size(); j++) {
- // if (bb) {
- // if (s1[j] == ':') {
- // bb = false;
- // continue;
- // }
- // hh *= 10;
- // hh += s1[j] - '0';
- // } else {
- // mm1 *= 10;
- // mm1 += s1[j] - '0';
- // }
- // }
- int ss = h * 60 + m1;
- int ss1 = hh * 60 + mm1;
- if (ss1 < ss) {
- ss1 += 24 * 60;
- }
- for (int j = 0; j <= 2; j++) {
- m[a - 1][ss + j * 1440]--;
- m[b - 1][ss1 + j * 1440]++;
- }
- in[b - 1]++;
- out[a - 1]++;
- }
- for (int i = 0; i < n; i++) {
- if (in[i] != out[i]) {
- cout << -1 << endl;
- return 0;
- }
- }
- int ans = 0;
- for (int i = 0; i < n; i++) {
- int k = 0;
- for (int j = 0; j <= 2880; j++) {
- k += m[i][j];
- if (k < 0) {
- ans += -k;
- k = 0;
- }
- }
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement