6521 | 2023-12-06 09:42:26 | EsVagy | Videójáték | cpp17 | Accepted 100/100 | 181ms | 9388 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1684 KiB | ||||
2 | Accepted | 3ms | 2004 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 3ms | 2168 KiB | ||||
4 | Accepted | 3ms | 2288 KiB | ||||
5 | Accepted | 3ms | 2508 KiB | ||||
6 | Accepted | 3ms | 2748 KiB | ||||
7 | Accepted | 3ms | 2952 KiB | ||||
8 | Accepted | 3ms | 3176 KiB | ||||
9 | Accepted | 3ms | 3384 KiB | ||||
10 | Accepted | 3ms | 3436 KiB | ||||
11 | Accepted | 3ms | 3680 KiB | ||||
subtask3 | 20/20 | ||||||
12 | Accepted | 3ms | 3692 KiB | ||||
13 | Accepted | 3ms | 3692 KiB | ||||
14 | Accepted | 3ms | 3692 KiB | ||||
15 | Accepted | 3ms | 3816 KiB | ||||
16 | Accepted | 3ms | 3924 KiB | ||||
17 | Accepted | 4ms | 4040 KiB | ||||
18 | Accepted | 4ms | 4272 KiB | ||||
19 | Accepted | 4ms | 4232 KiB | ||||
20 | Accepted | 4ms | 4452 KiB | ||||
21 | Accepted | 4ms | 4444 KiB | ||||
22 | Accepted | 3ms | 4440 KiB | ||||
subtask4 | 30/30 | ||||||
23 | Accepted | 14ms | 4864 KiB | ||||
24 | Accepted | 48ms | 5940 KiB | ||||
25 | Accepted | 123ms | 8856 KiB | ||||
26 | Accepted | 136ms | 9340 KiB | ||||
27 | Accepted | 136ms | 9344 KiB | ||||
28 | Accepted | 54ms | 6824 KiB | ||||
29 | Accepted | 10ms | 5068 KiB | ||||
30 | Accepted | 10ms | 5148 KiB | ||||
31 | Accepted | 7ms | 4788 KiB | ||||
subtask5 | 40/40 | ||||||
32 | Accepted | 17ms | 5172 KiB | ||||
33 | Accepted | 59ms | 6180 KiB | ||||
34 | Accepted | 112ms | 7636 KiB | ||||
35 | Accepted | 158ms | 9272 KiB | ||||
36 | Accepted | 180ms | 9388 KiB | ||||
37 | Accepted | 181ms | 9336 KiB | ||||
38 | Accepted | 93ms | 7124 KiB | ||||
39 | Accepted | 112ms | 8676 KiB | ||||
40 | Accepted | 28ms | 5756 KiB | ||||
41 | Accepted | 45ms | 5888 KiB |