求助 P1094 [NOIP2007 普及组] 纪念品分组
查看原帖
求助 P1094 [NOIP2007 普及组] 纪念品分组
867819
Javie楼主2023/3/26 12:22

我不知道我的问题出在哪儿

#include<bits/stdc++.h>
typedef long long ll;
typedef double db;
using namespace std;
ll w,n,ans;
ll a[30010];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	cin>>w>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	ll *p;
	p=a;
	ll *q;
	q=a+n;
	
	for(ll i=0;i<n&&q>=p;i++)
	{
		if((*p+*q)>w)
		{
			q--;
			ans++;
		}
		else if((*q+*p)<=w)
		{
			q--;
			p++;
			ans++;
		}
	}
	cout<<ans;
	return 0;
}
2023/3/26 12:22
加载中...