65192023-12-06 09:31:52EsVagyVideójátékcpp17Wrong answer 10/100181ms37344 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
1Accepted3ms1816 KiB
2Accepted3ms2060 KiB
subtask210/10
3Accepted3ms2300 KiB
4Accepted3ms2544 KiB
5Accepted3ms2708 KiB
6Accepted3ms2956 KiB
7Accepted3ms3164 KiB
8Accepted3ms3360 KiB
9Accepted3ms3464 KiB
10Accepted3ms3596 KiB
11Accepted3ms3524 KiB
subtask30/20
12Accepted3ms3632 KiB
13Accepted3ms3876 KiB
14Accepted3ms3940 KiB
15Accepted3ms3944 KiB
16Accepted3ms4064 KiB
17Accepted4ms4232 KiB
18Accepted4ms4344 KiB
19Accepted4ms4328 KiB
20Wrong answer4ms4380 KiB
21Wrong answer4ms4416 KiB
22Wrong answer3ms4440 KiB
subtask40/30
23Accepted14ms5148 KiB
24Accepted50ms7036 KiB
25Accepted126ms12116 KiB
26Accepted143ms14704 KiB
27Accepted137ms17244 KiB
28Accepted54ms15696 KiB
29Wrong answer12ms14460 KiB
30Wrong answer10ms14576 KiB
31Accepted7ms14616 KiB
subtask50/40
32Wrong answer17ms15140 KiB
33Accepted61ms17328 KiB
34Accepted112ms21108 KiB
35Accepted159ms26004 KiB
36Accepted180ms29824 KiB
37Accepted181ms33364 KiB
38Wrong answer94ms33380 KiB
39Wrong answer114ms37344 KiB
40Accepted29ms34844 KiB
41Wrong answer45ms35756 KiB