Tên đăng nhập Điểm ▾ Bài tập Giới thiệu
261 801 1
261 801 1
261 801 1
264 765 1
265 738 3
266 730 2
267
nio_yuzu 1899
dep trai khong ai sanh bang
487 16
268
Lê_Bào888 1285
Lê Văn Gia Bảo
459 32

25/3/2024-6/11/2024

269 433 6
270 360 1
270 360 1
270 360 1
270 360 1
270 360 1
270 360 1
270 360 1
270 360 1
270 360 1
270 360 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;

}

280
huuthinh222010
Nguyễn Hữu Thịnh
83 7