sorting, two pointers(cf div.3 1113)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sorting, two pointers(cf div.3 1113)相关的知识,希望对你有一定的参考价值。
?????????alt main tin .com png bit include bsp clu
?????????????????????a balanced team, ????????????????????????????????????5???????????????????????????
1 #include <bits/stdc++.h> 2 using namespace std; 3 int n,a[200005]; 4 int main() 5 { 6 scanf("%d",&n); 7 for(int i=1;i<=n;i++)scanf("%d",&a[i]); 8 sort(a+1,a+n+1); 9 int j=n,ans=0; 10 for(int i=n;i>=1;i--){ 11 while(a[i]-a[j]<=5 && j>=1) 12 if(a[i]-a[j]<=5){ 13 j--; 14 ans=max(i-j,ans);} 15 } 16 printf("%d ",ans); 17 }
以上是关于sorting, two pointers(cf div.3 1113)的主要内容,如果未能解决你的问题,请参考以下文章
java 88. Merge Sorted Array(#Two Pointers).java
java 88. Merge Sorted Array(#Two Pointers).java
java 88. Merge Sorted Array(#Two Pointers).java
java 88. Merge Sorted Array(#Two Pointers).java