Submission #2122262


Source Code Expand

#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
inline int read(){
	int n=0,f=1;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if (c=='-') c=getchar(),f=-1;
	for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-48;
	return n*f;
}
const int maxn=2e5+5;
int n,m,i,j,ans;
struct ar{
	int l,r;
}a[maxn];
bool cmp(ar a,ar b){
	return (a.l==b.l)?a.r<b.r:a.l<b.l;
}
priority_queue<int>p;
bool bz[maxn];
int q[maxn],cnt;
int main(){
	n=read(),m=read();
	fo(i,1,n) a[i].l=read(),a[i].r=read();
	sort(a+1,a+1+n,cmp);
	j=1,ans=n;
	fo(i,1,n){
		if (j<=a[i].l&&j<=m) bz[j++]=1,ans--,p.push(-a[i].r);
		else{
			if (!p.empty()){
				int t=-p.top();
				if (t<a[i].r) p.pop(),p.push(-a[i].r),q[++cnt]=t;else
				q[++cnt]=a[i].r;
			}else q[++cnt]=a[i].r;
		}
	}
	sort(q+1,q+1+cnt);
	fd(i,m,1) if (bz[i]) break;else{
		for(;cnt&&i<q[cnt];cnt--);
		if (cnt) cnt--,ans--;else break;
	}
	printf("%d\n",ans); 
}

Submission Info

Submission Time
Task F - Exhausted?
User Drin_E
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 1088 Byte
Status AC
Exec Time 60 ms
Memory 3320 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 4
AC × 48
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt, s4.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt AC 49 ms 2556 KB
02.txt AC 26 ms 1916 KB
03.txt AC 53 ms 3320 KB
04.txt AC 53 ms 3320 KB
05.txt AC 2 ms 384 KB
06.txt AC 36 ms 2172 KB
07.txt AC 60 ms 2812 KB
08.txt AC 53 ms 3320 KB
09.txt AC 57 ms 2940 KB
10.txt AC 12 ms 1024 KB
11.txt AC 55 ms 2560 KB
12.txt AC 40 ms 1920 KB
13.txt AC 53 ms 2560 KB
14.txt AC 53 ms 2560 KB
15.txt AC 54 ms 2560 KB
16.txt AC 31 ms 1788 KB
17.txt AC 54 ms 2812 KB
18.txt AC 54 ms 2812 KB
19.txt AC 48 ms 2556 KB
20.txt AC 54 ms 2812 KB
21.txt AC 11 ms 896 KB
22.txt AC 54 ms 2812 KB
23.txt AC 8 ms 640 KB
24.txt AC 54 ms 2812 KB
25.txt AC 21 ms 2048 KB
26.txt AC 19 ms 1920 KB
27.txt AC 19 ms 2432 KB
28.txt AC 20 ms 2560 KB
29.txt AC 33 ms 3064 KB
30.txt AC 33 ms 3064 KB
31.txt AC 54 ms 2812 KB
32.txt AC 47 ms 2556 KB
33.txt AC 54 ms 2812 KB
34.txt AC 35 ms 1916 KB
35.txt AC 27 ms 1660 KB
36.txt AC 56 ms 2812 KB
37.txt AC 1 ms 256 KB
38.txt AC 1 ms 256 KB
39.txt AC 1 ms 256 KB
40.txt AC 1 ms 256 KB
41.txt AC 1 ms 256 KB
42.txt AC 1 ms 256 KB
43.txt AC 1 ms 256 KB
44.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB
s4.txt AC 1 ms 256 KB