2510 2023. 01. 15 11:41:31 HorakZsofi Videójáték cpp11 Accepted 100/100 178ms 7592 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int t, n;
	cin>>t>>n;
	vector<pair<int, int>> fsz(n+1);
	for(int i=1; i<n+1; i++){
		cin>>fsz[i].first;
		cin>>fsz[i].second;
	}
	int m;
	cin>>m;
	vector<pair<int, int>> haha(m+1);
	for(int i=1; i<m+1; i++){
		cin>>haha[i].first;
		cin>>haha[i].second;
	}
	int megoldas=0;
	int hszaml=1;
	for(int i=1; i<n+1; i++) {
		//itt megjön a főszereplő az i. szünetre

		/*
		amíg hszaml szünet intervallum az túl kicsi, addig fellépegetünk

		...utána most már a közös szünetes dolgokat vizsgáljuk

		...és utána ha elment a főszereplő, vagy már túl messze van a hszaml szünet, akkor kilépünk
		*/
		while(hszaml<=m && haha[hszaml].second<fsz[i].first){
			hszaml++;
		}
		if(hszaml>m) {
			break;
		}

		int fszido=fsz[i].first;
		while(1) {
			if(haha[hszaml].first>fsz[i].second){
				break;
			}
			if(fszido+t<haha[hszaml].first){
				break;
			}
			int mini=min(haha[hszaml].second, fsz[i].second);
			int maxi=max(haha[hszaml].first, fszido);
			megoldas+=mini-maxi+1;
			
			if(i+1<=n){
				if( fsz[i+1].first>haha[hszaml].second){
					hszaml++;
				} else {
					break;
				}
			}
			else{
				hszaml++;
			}
			fszido=mini+1;
			if(hszaml>m) {
				break;
			}
		}
	}
	cout<<megoldas;
}
Subtask Sum Test Verdict Time Memory
subtask1 0/0
1 Accepted 3ms 1812 KiB
2 Accepted 2ms 2056 KiB
subtask2 10/10
3 Accepted 2ms 2124 KiB
4 Accepted 2ms 2376 KiB
5 Accepted 2ms 2624 KiB
6 Accepted 2ms 2780 KiB
7 Accepted 2ms 3020 KiB
8 Accepted 2ms 3236 KiB
9 Accepted 2ms 3280 KiB
10 Accepted 2ms 3520 KiB
11 Accepted 2ms 3668 KiB
subtask3 20/20
12 Accepted 2ms 3868 KiB
13 Accepted 2ms 3948 KiB
14 Accepted 2ms 4180 KiB
15 Accepted 2ms 4292 KiB
16 Accepted 3ms 4496 KiB
17 Accepted 3ms 4496 KiB
18 Accepted 3ms 4456 KiB
19 Accepted 4ms 4464 KiB
20 Accepted 3ms 4464 KiB
21 Accepted 3ms 4692 KiB
22 Accepted 2ms 4788 KiB
subtask4 30/30
23 Accepted 14ms 4916 KiB
24 Accepted 48ms 5540 KiB
25 Accepted 119ms 7296 KiB
26 Accepted 133ms 7592 KiB
27 Accepted 133ms 7556 KiB
28 Accepted 52ms 5940 KiB
29 Accepted 10ms 4972 KiB
30 Accepted 9ms 4848 KiB
31 Accepted 6ms 4692 KiB
subtask5 40/40
32 Accepted 17ms 4924 KiB
33 Accepted 59ms 5472 KiB
34 Accepted 112ms 6704 KiB
35 Accepted 157ms 7072 KiB
36 Accepted 178ms 7552 KiB
37 Accepted 178ms 7556 KiB
38 Accepted 92ms 6584 KiB
39 Accepted 111ms 6972 KiB
40 Accepted 28ms 5156 KiB
41 Accepted 43ms 5728 KiB