标签:blog io os sp for div log bs as
习题8-1 Uva1149 11.8
#include <iostream> #include <algorithm> using namespace std; int main() { int n, m, mi; int w[100005]; int num; int l, r; cin>>n>>m; for(int i = 1; i <= n; i++) { cin>>w[i]; } sort(w+1, w+n+1); l = 1 , r = n; num = 0; while(l!=r) { mi = m; if(w[l] <= mi) { mi-=w[l]; l++; } else { cout<<"No Answer!"<<endl; return 0; } if(w[r] <= mi) r--; num++; } cout<<num<<endl; return 0; }
标签:blog io os sp for div log bs as
原文地址:http://www.cnblogs.com/you-well-day-fine/p/4083874.html