40262023-03-09 11:55:49kdbVideójátékcpp17Time limit exceeded 0/1002.099s8908 KiB
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <tuple>

using namespace std;
signed  main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t, n;
    cin >> t >> n;
    vector<pair<int, int>> me;
    vector<pair<int, int>> huno;
    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        me.push_back(make_pair(x, y));
    }
    int m;
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        huno.push_back(make_pair(x, y));
    }
    int ans = 0;
    int lgame = me[0].first-1;
    int mei = 0;
    int hui = 0;
    while (true)
    {
        if (me[mei].first <= huno[hui].first && me[mei].second >= huno[hui].first)
        {
            if (lgame + t+1 >= huno[hui].first && lgame != me[mei].second)
            {
                ans += min(me[mei].second, huno[hui].second) - huno[hui].first + 1;
            }
        }
        if (me[mei].first >= huno[hui].first && me[mei].first <= huno[hui].second)
        {
            ans += min(me[mei].second, huno[hui].second) - me[mei].first + 1;
        }
        if (me[mei].second >= huno[hui].second)
        {
            if (lgame < huno[hui].second)
            {
                lgame = huno[hui].second;
                hui++;
            }
            if (hui == m)
            {
                cout << ans;
                return 0;
            }
        }
        else {
            mei++;
            if (mei == n)
            {
                cout << ans;
                return 0;
            }
            lgame = me[mei].first - 1;
        }
    }
}
/*
25 7
1 8 3 15 4 20 16
*/
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Accepted3ms2016 KiB
subtask20/10
3Accepted3ms2228 KiB
4Accepted3ms2444 KiB
5Accepted3ms2672 KiB
6Time limit exceeded2.099s2872 KiB
7Accepted3ms3108 KiB
8Accepted2ms3180 KiB
9Accepted3ms3292 KiB
10Accepted2ms3364 KiB
11Wrong answer2ms3356 KiB
subtask30/20
12Time limit exceeded2.078s3468 KiB
13Time limit exceeded2.048s3556 KiB
14Time limit exceeded2.059s3944 KiB
15Time limit exceeded2.066s3916 KiB
16Time limit exceeded2.066s3276 KiB
17Time limit exceeded2.072s3920 KiB
18Time limit exceeded2.063s4180 KiB
19Time limit exceeded2.043s3496 KiB
20Time limit exceeded2.072s4344 KiB
21Time limit exceeded2.059s3480 KiB
22Time limit exceeded2.062s4204 KiB
subtask40/30
23Time limit exceeded2.075s3728 KiB
24Time limit exceeded2.069s4224 KiB
25Time limit exceeded2.072s5856 KiB
26Wrong answer43ms8876 KiB
27Wrong answer43ms8908 KiB
28Time limit exceeded2.059s4684 KiB
29Time limit exceeded2.075s4840 KiB
30Time limit exceeded2.063s3804 KiB
31Time limit exceeded2.063s3576 KiB
subtask50/40
32Time limit exceeded2.059s3844 KiB
33Time limit exceeded2.061s4408 KiB
34Time limit exceeded2.063s5172 KiB
35Time limit exceeded2.069s5940 KiB
36Time limit exceeded2.075s6040 KiB
37Time limit exceeded2.075s6040 KiB
38Time limit exceeded2.068s4956 KiB
39Time limit exceeded2.059s6300 KiB
40Time limit exceeded2.063s4708 KiB
41Time limit exceeded2.059s4532 KiB