30分求调
查看原帖
30分求调
1174603
ruigemeikun楼主2024/11/29 19:11
#include<bits/stdc++.h>
using namespace std;
int main(){	
    long long n,w,a[100],s=0,x=0;
	cin>>n>>w;
	for(int i=0;i<n;i++){
		cin>>a[i];
	} 
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(x+a[i]<=w){
			x+=a[i];	
		}
		else{
			i--;
			s++;
			x=0;
		}
	}
	if(x>0){
		s++;		
	}
	cout<<s;
	return 0;
}
2024/11/29 19:11
加载中...