codeforce C. Save the Nature (前缀、二分)

题目:https://codeforces.com/contest/1223/problem/C

注意:二分的写法,容易搞错

#include
#define LL long long
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
const int maxn=200005;
const int mod=1e9+7;
LL p[maxn];
LL x,a,y,b,k;
LL sum[maxn];
LL gcd(LL a,LL b)
{
	if(b==0) return a;
	return gcd(b,a%b);
}
bool cmp(LL a,LL b)
{
	return a>b;
}
int main()
{
	ios::sync_with_stdio(false);
	int q;
	cin>>q;
	while(q--)
	{
		int n;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>p[i];
		}
		sort(p+1,p+n+1,cmp);
		sum[0]=0;
		for(int i=1;i<=n;i++)
		{
			sum[i]=sum[i-1]+p[i];
		}
		cin>>x>>a>>y>>b>>k; 
		if(x=k)
			{
				//ans=mid;
				r=mid-1;
			}
			else
			{
				l=mid+1;
			}
		}
		if(l>n)
			cout << -1 << endl;
		else
			cout << l << endl;
	} 
	return 0;	
}

 

你可能感兴趣的:(acm)