Anhtt
Rating
-
Bài tập
1
Điểm
6
Rating #
-
Điểm #
318
Giới thiệu
include <bits/stdc++.h>
define task "PPOINT"
define ll long long
define fi first
define se second
define pb push_back
using namespace std;
const int N = 1e6 + 5;
int n, cnt[5], ans = INT_MAX, l = 1, r = 1;
pair<int, int> p[N];
main() {
cin.tie(0)->sync_with_stdio(0);
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> p[i].fi >> p[i].se;
}
sort(p + 1, p + n + 1);
while(l <= n && r <= n) {
cnt[p[r].se]++;
while(cnt[1] > 0 && cnt[2] > 0 && cnt[3] > 0 && l < r) {
ans = min(ans, p[r].fi - p[l].fi);
cnt[p[l].se]--;
l++;
}
r++;
}
cout << ans;
return 0;
}