7-1
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> using namespace std; const int maxn=10014; int main () { int N; scanf ("%d",&N); int a[maxn],sum=-1,tmp=0,left=0,right=N-1,tmpindex=0; for (int i=0;i<N;i++) { scanf ("%d",&a[i]); tmp+=a[i]; if (tmp<0) { tmp=0; tmpindex=i+1; } else if (tmp>sum) { sum=tmp; left=tmpindex; right=i; } } if (sum<0) sum=0; printf ("%d %d %d",sum,a[left],a[right]); return 0; }
7-2
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> using namespace std; const int maxn=100010; int n,p,a[maxn]; int main () { scanf ("%d%d",&n,&p); for (int i=0;i<n;i++) scanf ("%d",&a[i]); sort (a,a+n); int ans=1; for (int i=0;i<n;i++) { int j=upper_bound(a+i+1,a+n,(long long)a[i]*p)-a; ans=max(ans,j-i); } printf ("%d\n",ans); return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> using namespace std; const int maxn=1e6+14; typedef long long ll; ll a[maxn]; int binarySearch (int l,int r,ll x) { while (l<r) { int mid=(l+r)>>1; if (a[mid]<=x) l=mid+1; else r=mid; } return l; } int main () { int N,P; scanf("%d%d",&N,&P); for (int i=0;i<N;i++) scanf("%lld",&a[i]); sort(a,a+N); int ans=1; int maxans=0; for (int i=0;i<N-1;i++) { int j=binarySearch(i+1,N,(ll)a[i]*P); ans=max(ans,j-i); } printf ("%d",ans); return 0; }