64482023-11-30 15:57:55gergomiszoriÁruszállítás üres szakaszaicpp17Wrong answer 14/5052ms7180 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define endl "\n"
#define pll pair<ll,ll>
#define fs first
#define sc second 
 
void solve()
{
	ll n, m;
	cin >> n >> m;
	vector<ll> a(m), b(m);
	for(ll i = 0; i < m; i++) cin >> a[i] >> b[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	ll db = 0;
	bool ures = false;
	ll ans = 0;
	ll ai = 0, bi = 0;
	for(ll i = 1; i <= n; i++)
	{
		while(a[ai] < i && ai+1 < a.size()) ai++;
		while(b[bi] < i && bi+1 < b.size()) bi++;
		while(ai < a.size() && a[ai] == i)
		{
			db++;
			ai++;
			ures = false;
		}
		while(bi < b.size() && b[bi] == i)
		{
			db--;
			bi++;
			ures = false;
		}
		if(!ures && db == 0) 
		{
			ans++;
			ures = true;
		}
	}
	cout << ans << endl;
}
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	ll t = 1;
    	//cin >> t;
    	while(t--)
    	{
        	solve();
    	}
    	return 0;
}
SubtaskSumTestVerdictTimeMemory
base14/50
1Accepted0/03ms1828 KiB
2Wrong answer0/052ms5084 KiB
3Accepted2/23ms2332 KiB
4Wrong answer0/23ms2448 KiB
5Accepted2/22ms2524 KiB
6Accepted2/23ms2656 KiB
7Accepted2/23ms2884 KiB
8Accepted2/22ms2944 KiB
9Wrong answer0/22ms3096 KiB
10Wrong answer0/23ms3184 KiB
11Accepted2/23ms3272 KiB
12Accepted2/23ms3404 KiB
13Wrong answer0/34ms3576 KiB
14Wrong answer0/37ms3628 KiB
15Wrong answer0/34ms3452 KiB
16Wrong answer0/334ms5756 KiB
17Wrong answer0/334ms5756 KiB
18Wrong answer0/339ms6276 KiB
19Wrong answer0/38ms3916 KiB
20Wrong answer0/38ms4240 KiB
21Wrong answer0/348ms7100 KiB
22Wrong answer0/350ms7180 KiB