简单贪心。注意内存够大,能满足所有顾客的特殊情况。
1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 5 #define maxn 100010 6 7 using namespace std; 8 9 typedef long long ll; 10 11 struct node { 12 ll c,id; 13 }c[maxn]; 14 15 bool cmp (node x,node y){ 16 if (x.c<y.c) 17 return true ; 18 return false ; 19 } 20 21 int main (){ 22 ll n,d,x,y,a,b; 23 ll ans,sum; 24 while (cin>>n>>d){ 25 cin>>a>>b; 26 for (int i=0;i<n;i++){ 27 cin>>x>>y; 28 c[i].c=a*x+b*y; 29 c[i].id=i+1; 30 } 31 sort (c,c+n,cmp); 32 sum=ans=0; 33 for (int i=0;i<n;i++){ 34 sum+=c[i].c; 35 if (sum>d){ 36 ans=i; 37 break ; 38 } 39 if (i==n-1) //所有顾客都能满足 40 ans=n; 41 } 42 cout<<ans<<endl; 43 for (int i=0;i<ans;i++){ 44 cout<<c[i].id<<" "; 45 } 46 cout<<endl; 47 } 48 return 0; 49 }