Tên đăng nhập Điểm ▾ Bài tập Giới thiệu
301 9 4
302 9 3
303 9 1
304 9 2

Ba Đồn

305 8 2
306 8 1
306 8 1
306 8 1
306 8 1
306 8 1
306 8 1
306 8 1
306 8 1
306 8 1
306 8 1
306 8 1
306 8 1
306 8 1
306 8 1
320 8 2
320 8 2
320 8 2
323 7 2
324
HoangThanhDuc__HongThuy 1189
HoangThanhDuc_HongThuy
7 2
325 6 1
326 6 1
327 6 1
327
viet_hoang666301
duong hoang an
6 1
327
thientri0307_hoathinguyen 1151
Nguyễn Thị Hoa
6 1
327 6 1
327 6 1
327 6 1
327 6 1
327
Dukey 1589
6 1
327 6 1
327 6 1
327 6 1
327 6 1
327 6 1
327 6 1
327 6 1
327 6 1

No cap

327 6 1
327 6 1
327 6 1
327 6 1
327 6 1
327 6 1
327 6 1
327 6 1
327 6 1
327 6 1
327 6 1

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;

}

327 6 1
327 6 1
327 6 1
327 6 1
327 6 1
327
ngocnhi5a 1313
Nguyễn Lê Ngọc Nhi
6 1
327
Haoct 1145
6 1
327 6 1
327 6 1
327 6 1
327 6 1
327 6 1
327 6 1

anh xin tự giới thiệu anh là công tử bạc liêu

327 6 1
327 6 1
327 6 1
327 6 1
371 6 2
371 6 2
371 6 2
374
ropansknslig
Nguyễn Anh Quân
5 2
375
thinh 1055
5 2
376 5 1
376 5 1
376 5 1
376 5 1
376 5 1
381 5 1
381 5 1
383 5 1
383 5 1
385 5 1
386 4 2
387 4 1
387 4 1
387 4 1
387 4 1
387 4 1
387 4 1
387 4 1
387 4 1
387 4 1
387 4 1
387 4 1
387
namlong123456
Ngyễn Nam Long
4 1
387 4 1
387 4 1