51Nod1432独木舟

题目信息

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n,m,a[10005];
	while(cin>>n>>m) {
		for(int i=0; i<n; i++)
			cin>>a[i];
		sort(a,a+n);
		int ans=0;
		for(int i=0,j=n-1; i<=j;) {
			if(a[j]+a[i]<=m) {//如果能载两个人 
				ans++;
				i++;
				j--;
			} else {//只能载最重的那个 
				ans++;
				j--;
			}
		}
		cout<<ans<<endl;
	}
}

猜你喜欢

转载自blog.csdn.net/qq_39564498/article/details/81205809