水题,直接贴代码。
//poj 2497 //sep9 #include <iostream> #include <algorithm> using namespace std; int a[32]; int main() { int cases,c=0; scanf("%d",&cases); while(cases--){ int tot,n; scanf("%d%d",&tot,&n); int x2,y2,t; for(int i=0;i<n;++i) scanf("%d",&a[i]); x2=0,y2=0,t=0; sort(a,a+n); while(x2<n&&t+a[x2]<=tot){ y2+=t+a[x2]; t+=a[x2]; ++x2; } printf("Scenario #%d:\nSteve wins with %d solved problems and a score of %d.\n\n",++c,x2,y2); } return 0; }
原文地址:http://blog.csdn.net/sepnine/article/details/45174509