AcWing 1238. 日志统计
原题链接
中等
作者:
扑流萤
,
2024-02-29 09:26:38
,
所有人可见
,
阅读 31
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;
const int N = 1e5+5;
#define x first
#define y second
PII a[N]; // x: 点赞id、y: 点赞时间
int n,D,K;
bool judge(int begin, int end) {
for(int i = begin; i <= end; i ++) {
int j = i + K - 1;
if(j > end) return 0;
if(a[j].y - a[i].y < D) return 1;
}
return 0;
}
int main() {
cin >> n >> D >> K;
for (int i = 0; i < n; i ++ ) {
cin >> a[i].y >> a[i].x;
}
sort(a, a + n);
for (int i = 0; i < n; i ++ ) {
int j = i + 1;
while(a[i].x == a[j].x) {
j++;
}
j--;
if(judge(i, j)) {
cout << a[i].x << endl;
}
i = j;
}
return 0;
}