hack:
```
8 4
1001 99
1002 97
1003 91
1004 74
1005 72
1006 35
1007 29
1008 23
```
正确输出:
```
35 6
1001 99
1002 97
1003 91
1004 74
1005 72
1006 35
```
你的程序运行到第28行的时候,此时 $i=7$。你发现 $29 < 35$!此时,$n$ 变成了 $7$。循环结束之后,$i$ 变成了 $8$。你发现 $i>n$!所以循环结束了。正常来讲,最后一行也应该被算一次。
改成这样:
```cpp
#include<bits/stdc++.h>
using namespace std;
struct f{
int id;
int score;
};
bool cmp(f a , f b)
{
if(a.score>b.score) return 1;
else if(a.score==b.score&&a.id<b.id) return 1;
return 0;
}
f human[15000];
int n , m ;
int wire,num,cnt;
int main()
{
scanf("%d%d", &n , &m ) ;
for(int i = 1 ; i <= n ; i ++)
{
scanf("%d%d", &human[i].id , &human[i].score);
}
sort(human + 1 , human + 1 + n , cmp );
wire=m*1.5;
num=human[wire].score;
cnt=n;
for(int i=1;i<=n;i++)
{
if(human[i].score<num) cnt--;
}
cout<<num<<" "<<cnt<<endl;
for(int i=1;i<=cnt;i++)
{
cout<<human[i].id<<" "<<human[i].score<<endl;
}
return 0;
}
```
**应该** 就好了。
by Hankler @ 2024-04-30 21:15:35
@[python18](/user/1182672)
by Hankler @ 2024-04-30 21:17:32
@[Hankler](/user/692338) 改了25至30行。
by Hankler @ 2024-04-30 21:23:43
@[python18](/user/1182672) 看完AC了吱一声儿啊!awa
by Hankler @ 2024-04-30 21:39:53
@[Hankler](/user/692338)
谢谢喵
by python18 @ 2024-05-01 07:44:54