-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13334.cpp
More file actions
57 lines (41 loc) · 1 KB
/
13334.cpp
File metadata and controls
57 lines (41 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
typedef pair<int, int> pii;
int n, d;
vector<pii> list;
struct comp{
bool operator()(pii a, pii b){
if(a.first==b.first) return a.second>b.second;
return a.first>b.first;
}
};
bool compare(pii a, pii b){
if(a.second==b.second) return a.first<b.first;
return a.second<b.second;
}
priority_queue<pii, vector<pii>, comp> pq;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int i, j, a, b;
int ans = 0;
cin >> n;
for(i=1; i<=n; i++){
cin >> a >> b;
if(a>b) list.push_back({b, a});
else list.push_back({a, b});
}
cin >> d;
sort(list.begin(), list.end(), compare);
for(i=0; i<n; i++){
if(list[i].second-list[i].first>d) continue;
pq.push(list[i]);
while(!pq.empty() && pq.top().first<list[i].second-d) pq.pop();
ans = max(ans, int(pq.size()));
}
cout << ans;
return 0;
}