65212023-12-06 09:42:26EsVagyVideójátékcpp17Accepted 100/100181ms9388 KiB
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <queue>
#include <fstream>
#include <sstream>
#include <math.h>

using namespace std;

int main()
{
    int t;
    int n, m;
    vector<pair<int, int>> breaks;
    vector<pair<int, int>> friendBreaks;

    cin >> t;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int first, second;
        cin >> first >> second;
        breaks.push_back(pair<int, int>(first, second));
    }
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        int first, second;
        cin >> first >> second;
        friendBreaks.push_back(pair<int, int>(first, second));
    }

    int sum = 0;
    int breakIndex = 0;
    int friendBreakIndex = 0;
    while (breakIndex < breaks.size() && friendBreakIndex < friendBreaks.size())
    {
        pair<int, int> match = pair<int, int>(max(breaks[breakIndex].first, friendBreaks[friendBreakIndex].first), min(breaks[breakIndex].second, friendBreaks[friendBreakIndex].second));
        if (match.first > match.second)
        {
            if (breaks[breakIndex].first > friendBreaks[friendBreakIndex].second)
            {
                friendBreakIndex++;
                continue;
            }
            else
            {
                breakIndex++;
                continue;
            }
        }
        if (match.first > breaks[breakIndex].first + t)
        {
            breakIndex++;
            continue;
        }
        sum += match.second - match.first + 1;
        if (breaks[breakIndex].second < friendBreaks[friendBreakIndex].second)
        {
            breakIndex++;
        }
        else if (breaks[breakIndex].second > friendBreaks[friendBreakIndex].second)
        {
            breaks[breakIndex].first = friendBreaks[friendBreakIndex].second;
            friendBreakIndex++;
        }
        else
        {
            breakIndex++;
            friendBreakIndex++;
        }
    }

    cout << sum;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1684 KiB
2Accepted3ms2004 KiB
subtask210/10
3Accepted3ms2168 KiB
4Accepted3ms2288 KiB
5Accepted3ms2508 KiB
6Accepted3ms2748 KiB
7Accepted3ms2952 KiB
8Accepted3ms3176 KiB
9Accepted3ms3384 KiB
10Accepted3ms3436 KiB
11Accepted3ms3680 KiB
subtask320/20
12Accepted3ms3692 KiB
13Accepted3ms3692 KiB
14Accepted3ms3692 KiB
15Accepted3ms3816 KiB
16Accepted3ms3924 KiB
17Accepted4ms4040 KiB
18Accepted4ms4272 KiB
19Accepted4ms4232 KiB
20Accepted4ms4452 KiB
21Accepted4ms4444 KiB
22Accepted3ms4440 KiB
subtask430/30
23Accepted14ms4864 KiB
24Accepted48ms5940 KiB
25Accepted123ms8856 KiB
26Accepted136ms9340 KiB
27Accepted136ms9344 KiB
28Accepted54ms6824 KiB
29Accepted10ms5068 KiB
30Accepted10ms5148 KiB
31Accepted7ms4788 KiB
subtask540/40
32Accepted17ms5172 KiB
33Accepted59ms6180 KiB
34Accepted112ms7636 KiB
35Accepted158ms9272 KiB
36Accepted180ms9388 KiB
37Accepted181ms9336 KiB
38Accepted93ms7124 KiB
39Accepted112ms8676 KiB
40Accepted28ms5756 KiB
41Accepted45ms5888 KiB