2026-11-22 17:30:35
发布于:浙江
帮我看一下我错哪了吧
#include <bits/stdc++.h>
using namespace std;
struct XT{
int x,t;
}a[100010];
bool cmp(XT xx,XT tt){
if (xx.x != tt.x) return xx.x < tt.x;
else return xx.t < tt.t;
}
int n,cnt = 0,dp[100010],mx = 0;
int main(){
cin >> n;
for (int i = 1;i <= n;i++){
int x,t;
cin >> x >> t;
if (x <= t){
++cnt;
a[cnt].x = x;
a[cnt].t = t;
}
}
sort(a + 1,a + cnt + 1,cmp);
int len = 0;
for (int i = 1;i <= cnt;i++){
int z = a[i].x - a[i].t;
int idx = lower_bound(dp + 1,dp + len + 1,z,greater<int>()) - dp;
if(idx > len){
dp[++len] = z;
}else{
dp[idx] = z;
}
}
cout << len;
return 0;
}
全部评论 1

昨天 来自 浙江
0哪道题?
昨天 来自 湖北
0



















有帮助,赞一个