• LTOJ
  • Trang chủ
  • Bài tập
  • Bài nộp
  • Thành viên
  • Kỳ thi
  • Chat
  • Tổ chức
  • Discord
  • giới thiệu
  • courses

Tiếng Việt

Tiếng Việt
English

Đăng nhập

Đăng ký

Anhtt

  • Giới thiệu
  • Bài tập
  • Bài nộp

Rating
-
Bài tập
1
Điểm
6
Rating #
-
Điểm #
322

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;

}


«    »
Thứ 2
Thứ 3
Thứ 4
Thứ 5
Thứ 6
Thứ 7
CN
Ít
Nhiều

proudly powered by DMOJ| developed by LQDJudge team