65202023-12-06 09:35:16EsVagyVideójátékcpp17Wrong answer 10/100180ms9040 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 + 1;
            friendBreakIndex++;
        }
        else
        {
            breakIndex++;
            friendBreakIndex++;
        }
    }

    cout << sum;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1688 KiB
2Accepted3ms1844 KiB
subtask210/10
3Accepted3ms2092 KiB
4Accepted3ms2180 KiB
5Accepted3ms2312 KiB
6Accepted3ms2548 KiB
7Accepted3ms2692 KiB
8Accepted3ms2944 KiB
9Accepted3ms3000 KiB
10Accepted3ms3132 KiB
11Accepted3ms3216 KiB
subtask30/20
12Accepted3ms3220 KiB
13Accepted3ms3340 KiB
14Accepted3ms3396 KiB
15Accepted3ms3544 KiB
16Accepted3ms3656 KiB
17Accepted4ms3860 KiB
18Accepted4ms3972 KiB
19Accepted4ms3972 KiB
20Wrong answer4ms4020 KiB
21Wrong answer3ms3980 KiB
22Wrong answer3ms4024 KiB
subtask40/30
23Accepted16ms4580 KiB
24Accepted50ms5492 KiB
25Accepted123ms8556 KiB
26Accepted136ms8540 KiB
27Accepted136ms8540 KiB
28Accepted54ms5956 KiB
29Wrong answer10ms4400 KiB
30Wrong answer10ms4468 KiB
31Accepted7ms4548 KiB
subtask50/40
32Wrong answer17ms5172 KiB
33Accepted59ms6116 KiB
34Accepted112ms7416 KiB
35Accepted159ms8984 KiB
36Accepted180ms8984 KiB
37Accepted180ms9040 KiB
38Wrong answer93ms7016 KiB
39Wrong answer112ms8452 KiB
40Accepted28ms5488 KiB
41Wrong answer43ms5672 KiB