【算法】贪心
【题解】比较经典,用l,r两个定位指针分别从左右向中间推进。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
#include#include #include using namespace std;const int maxn=10010;int n,m,a[maxn];int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++)scanf("%d",&a[i]); sort(a+1,a+n+1); int ans=0,l=1,r=n; while(l
本文共 381 字,大约阅读时间需要 1 分钟。
【算法】贪心
【题解】比较经典,用l,r两个定位指针分别从左右向中间推进。
#include#include #include using namespace std;const int maxn=10010;int n,m,a[maxn];int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++)scanf("%d",&a[i]); sort(a+1,a+n+1); int ans=0,l=1,r=n; while(l
转载于:https://www.cnblogs.com/onioncyc/p/7049471.html