求助91分,到底哪里错了
查看原帖
求助91分,到底哪里错了
590373
Jia807817368楼主2022/5/28 17:33
 #include<cstdio>
 #include<cstdlib>
 #include<map>
 #include<set>
 #include<cstring>
 #include<algorithm>
 #include<iostream>

 using namespace std;
 typedef long long LL;
 typedef pair<string, string> pr;
 
 int n;
 const int maxn = 5005;
 struct node{
     int l, w;
 }stick[maxn];
 int sss[maxn], cnt = 0;
 
 bool cmp(node a, node b)
 {
     return a.l > b.l;
 }
 
 int main()
 {
     scanf("%d", &n);
     for(int i = 1; i <= n; i++){
         scanf("%d%d", &stick[i].l, &stick[i].w);
     }
     
     sort(stick + 1, stick + 1 + n, cmp);
     
     for(int i = 1; i <= n; i++){
         if(stick[i].w > sss[cnt - 1]){
             sss[cnt++] = stick[i].w;
             //printf("%d", sss[cnt - 1]);
         }
         else{
             int pos = lower_bound(sss, sss + cnt, stick[i].w) - sss;
             sss[pos] = stick[i].w;
         }
     }
     printf("%d", cnt);
     
     return 0; 
 }
2022/5/28 17:33
加载中...