@[chanthu2114](/user/738212)
你根本没交过这题吧……
评测记录里没你的记录
by 82Young_UwU @ 2022-08-26 09:08:20
1. 你的排序过程是错的。首先循环的小括号里应该是 $m$ 而不是 $n$ ,然后你的排序有问题,你想写的可能是冒泡排序?
改成这样:
```cpp
for(int i=1;i<=m-1;i++)
for(int j=1;j<=m-i;j++)
if(a[j]>a[j+1])
{
tmp1=a[j];
a[j]=a[j+1];
a[j+1]=tmp1;
}
```
2. $cnt$ 在循环内部每一次都要清零。
3. 判断 `cnt++` 的 $if$ 语句改成:`if(a[j]>=i&&cnt<n)cnt++;` 首先是大于等于号,其次要判断 $cnt$ 是否小于 $n$,否则就大于仅有的 $n$ 批了。
by wanggk @ 2022-08-26 10:26:12
@[chanthu2114](/user/738212)
完整代码改成这样,可以过样例:
```cpp
#include<iostream>
using namespace std;
int a[1005],cnt,tmp1,tmp2=0,num;
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++)
cin>>a[i];
for(int i=1;i<=m-1;i++)
for(int j=1;j<=m-i;j++)
if(a[j]>a[j+1])
{
tmp1=a[j];
a[j]=a[j+1];
a[j+1]=tmp1;
}
for(int i=a[1];i<=a[m];i++)
{
cnt=0;
for(int j=1;j<=m;j++)
if(a[j]>=i&&cnt<n)cnt++;
tmp1=cnt*i;
if(tmp1>tmp2)
tmp2=tmp1,num=i;
}
cout<<num<<" "<<tmp2;
}
```
by wanggk @ 2022-08-26 10:26:40
@[chanthu2114](/user/738212)
还有就是我看到你 TLE 了,其实没必要每次都统计 cnt ,可以去看下题解。
by wanggk @ 2022-08-26 10:30:18
@所有帮我的大佬 嗯嗯,我懂了,谢谢你们!
by chanthu2114 @ 2022-08-26 15:21:41