标签:des style blog http color io os ar for
实在难想,贪心。别人的思路:点击打开链接
2 3 5 4 1 5 1 7 7 2 1 2 2 4 0
Case 1: 3 4 Case 2: 0 0
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn=1e5+10; struct node{ int w,s; }e[maxn]; int visit[maxn]; int t,n,s; int ans1,ans2,rs1,rs2; int cmp(node l1,node l2) { return l1.w<l2.w; } void solve_1() { int i; rs1=s; ans1=0; for(int i=0;i<n;i++) { if(e[i].s) continue; if(rs1>=e[i].w) { ans1++; rs1-=e[i].w; } else break; } } void solve_2() { int i; rs2=s; ans2=0; memset(visit,0,sizeof(visit)); for(i=0;i<n;i++) { if(e[i].s) break; } // cout<<"eeee "<<i<<endl; if(i>=n) return ; if(e[i].w>rs2) return ; int sum=0; for(int i=0;i<n;i++) sum+=e[i].s; // cout<<"222 "<<endl; if(sum+1>=n) {ans2=n;rs2-=e[i].w;return ;} // cout<<"11111 "<<endl; visit[i]=1; ans2=sum+1; rs2-=e[i].w; for(i=n-1;i>=0;i--) { if(!sum) break; if(!visit[i]) { visit[i]=1; sum--; } } for(i=0;i<n;i++) { // cout<<"fuck "<<endl; if(visit[i]) continue; if(rs2<e[i].w) break; ans2++; rs2-=e[i].w; } } int main() { int cas=0; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&s); for(int i=0;i<n;i++) scanf("%d%d",&e[i].w,&e[i].s); sort(e,e+n,cmp); solve_1(); solve_2(); // cout<<"fuck "<<ans1<<" "<<rs1<<" "<<ans2<<" "<<rs2<<endl; printf("Case %d: ",cas++); if(ans1>ans2||(ans1==ans2&&rs1>rs2)) printf("%d %d\n",ans1,s-rs1); else printf("%d %d\n",ans2,s-rs2); } return 0; }
标签:des style blog http color io os ar for
原文地址:http://blog.csdn.net/u013582254/article/details/39510685